walterbyrd a écrit :
On Dec 17, 8:41 am, prueba...@latinmail.com wrote:

If scoping worked as you want, how, pray tell, would you define object
attributes?- Hide quoted text -

I suppose you could do this:

class className():
    varname = "whatever"

This defines a class attribute - that is, an attribute of the className class object, accessible either thru the className object or it's instances if not shadowed by an instance attribute by the same name/

    def fname(self, varname):
       . . . .

Instead of having variable defined within methods to be global
everywhere within the class.

There's nothing like a "variable defined within (a) method", because you never define methods in Python - only functions. So there's no difference in scoping rules for functions defined within a class statement block or outside a class statement block.


Anyway, it's not a matter of what I like, I am just trying to
understand the reason behind the scoping rules.

Then you should start with understanding the scoping rules.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to