Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread r
I think there is a simpler answer to all this(not to take away from the other ones here though which are all great). When writing procedural code how would you like it if vars inside functions were automatically global. Your code with be blowing chunks in no time. Thats the reason for global

Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread Richard Brodie
walterbyrd walterb...@iname.com wrote in message news:518b9dd9-69c5-4d5b-bd5f-ad567be62...@b38g2000prf.googlegroups.com... However in the methods are within a class, the scoping seems to work differently. Not really, self is a formal parameter to the function. It would be a strange language

Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread John Machin
On Dec 18, 2:19 am, walterbyrd walterb...@iname.com wrote: For a language as well structured as Python, this seems somewhat sloppy, and inconsistant.  Or is there some good reason for this? Here is what I mean: def a():     x = 99     print x def b():     print x a() b() # raises an

Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread walterbyrd
On Dec 17, 10:00 am, r rt8...@gmail.com wrote: When writing procedural code how would you like it if vars inside functions were automatically global. Your code with be blowing chunks in no time. That was my point - I consider python's ordinary use of lexical scoping to be a good thing, and I

Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread walterbyrd
On Dec 17, 9:04 am, rdmur...@bitdance.com wrote: Yes.  It's called Object Oriented Programming. I think you mean it's *Python* Object Oriented Programming. I am not sure that every other OO language works like that. -- http://mail.python.org/mailman/listinfo/python-list

Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread walterbyrd
On Dec 17, 10:17 am, Richard Brodie r.bro...@rl.ac.uk wrote: Not really, self is a formal parameter to the function. It would be a strange language where a function's own arguments weren't in scope. Thank you, that makes sense to me. -- http://mail.python.org/mailman/listinfo/python-list

Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread r
On Dec 17, 12:20 pm, walterbyrd walterb...@iname.com wrote: On Dec 17, 10:00 am, r rt8...@gmail.com wrote: When writing procedural code how would you like it if vars inside functions were automatically global. Your code with be blowing chunks in no time. That was my point - I consider

Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread walterbyrd
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 def fname(self, varname): . . . . Instead of having

Why no lexical scoping for a method within a class?

2008-12-17 Thread rdmurray
Quoth walterbyrd walterb...@iname.com: For a language as well structured as Python, this seems somewhat sloppy, and inconsistant. Or is there some good reason for this? Yes. It's called Object Oriented Programming. Here is what I mean: def a(): x = 99 print x def b():

Why no lexical scoping for a method within a class?

2008-12-17 Thread walterbyrd
For a language as well structured as Python, this seems somewhat sloppy, and inconsistant. Or is there some good reason for this? Here is what I mean: def a(): x = 99 print x def b(): print x a() b() # raises an exception because x is not defined. However in the methods are

Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread pruebauno
On Dec 17, 10:19 am, walterbyrd walterb...@iname.com wrote: For a language as well structured as Python, this seems somewhat sloppy, and inconsistant.  Or is there some good reason for this? Here is what I mean: def a():     x = 99     print x def b():     print x a() b() # raises an

Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread Diez B. Roggisch
walterbyrd wrote: For a language as well structured as Python, this seems somewhat sloppy, and inconsistant. Or is there some good reason for this? Here is what I mean: def a(): x = 99 print x def b(): print x a() b() # raises an exception because x is not defined.

Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread Bruno Desthuilliers
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,

Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread Bruno Desthuilliers
walterbyrd a écrit : On Dec 17, 9:04 am, rdmur...@bitdance.com wrote: Yes. It's called Object Oriented Programming. I think you mean it's *Python* Object Oriented Programming. I am not sure that every other OO language works like that. Every OO languages having such a thing as a global

Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread Rhodri James
On Wed, 17 Dec 2008 15:19:32 -, walterbyrd walterb...@iname.com wrote: However in the methods are within a class, the scoping seems to work differently. Not really. Hopefully this commentary will show you why. class ab(): def a(self): self.x = 99 print self.x

Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread Chris Rebert
On Wed, Dec 17, 2008 at 4:03 PM, Rhodri James rho...@wildebst.demon.co.uk wrote: On Wed, 17 Dec 2008 15:19:32 -, walterbyrd walterb...@iname.com wrote: However in the methods are within a class, the scoping seems to work differently. Not really. Hopefully this commentary will show you

Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread Steven D'Aprano
On Wed, 17 Dec 2008 22:19:43 +0100, Bruno Desthuilliers wrote: Your problem is that you are confusing variables and attributes. In Python, 'anything.anyname' (note the dot) is the attribute 'anyname' of object 'anything'. An easy mistake to make, given that scopes are just namespaces, and

Re: Why no lexical scoping for a method within a class?

2008-12-17 Thread Steven D'Aprano
On Wed, 17 Dec 2008 10:20:21 -0800, walterbyrd wrote: On Dec 17, 10:00 am, r rt8...@gmail.com wrote: When writing procedural code how would you like it if vars inside functions were automatically global. Your code with be blowing chunks in no time. That was my point - I consider python's