Namespaces in functions vs classes

Ethan Furman ethan at
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?

"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))


What will serve print?


More information about the Python-list mailing list