Namespaces in functions vs classes

Ethan Furman ethan at stoneleaf.us
Sun Apr 17 16:25:23 EDT 2011


Gerald Britton wrote:
> However, I would like a deeper
> understanding of why I cannot use "foo" as an unqualified variable
> inside the method in the class. If Python allowed such a thing, what
> problems would that cause?

8<----------------------------------------------------
"script with possible name clashes"
eggs = 'scrambled eggs'
meat = 'steak'
class Breakfast():
 meat = 'spam'
 def serve(self):
 print("Here's your %s and %s!" %
 (eggs, meat))
Breakfast().serve()
8<----------------------------------------------------
What will serve print?
~Ethan~


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /