Re: Namespaces in functions vs classes

2011-04-19 Thread Gerald Britton
Ethan -- I'm just getting back to this question. If you recall, you asked: [snip] 8 script with possible name clashes eggs = 'scrambled eggs' meat = 'steak' class Breakfast(): meat = 'spam' def serve(self): print(Here's

Re: Namespaces in functions vs classes

2011-04-19 Thread Ethan Furman
Gerald Britton wrote: I now understand the Python does not consider a class definition as a separate namespace as it does for function definitions. That is a helpful understanding. That is not correct. Classes are separate namespaces -- they just aren't automatically searched. The only

Re: Namespaces in functions vs classes

2011-04-19 Thread Gerald Britton
Gerald Britton wrote: I now understand the Python does not consider a class definition as a separate namespace as it does for function definitions. That is a helpful understanding. That is not correct. Classes are separate namespaces -- they just aren't automatically searched. The only

Re: Namespaces in functions vs classes

2011-04-19 Thread Ian Kelly
On Tue, Apr 19, 2011 at 10:31 AM, Ethan Furman et...@stoneleaf.us wrote: Gerald Britton wrote: I now understand the Python does not consider a class definition as a separate namespace as it does for function definitions.  That is a helpful understanding. That is not correct.  Classes are

Re: Namespaces in functions vs classes

2011-04-19 Thread Terry Reedy
On 4/19/2011 10:58 AM, Gerald Britton wrote: serve method unless it is qualified. I now understand the Python does not consider a class definition as a separate namespace as it does for function definitions. Class namespaces are separate namespaces but not in the same way as for functions.

Re: Namespaces in functions vs classes

2011-04-19 Thread Rhodri James
On Tue, 19 Apr 2011 17:47:40 +0100, Gerald Britton gerald.brit...@gmail.com wrote: Gerald Britton wrote: I now understand the Python does not consider a class definition as a separate namespace as it does for function definitions. That is a helpful understanding. That is not correct.

Re: Namespaces in functions vs classes

2011-04-19 Thread Chris Angelico
On Wed, Apr 20, 2011 at 8:00 AM, Rhodri James rho...@wildebst.demon.co.uk wrote: Language abuse: it's not just Python.  A donation of just $5 will keep a programmer in prepositions for a month.  $50 will supply enough articles to keep a small company understandable for over a year.  With your

[OT] Piling of prepositions (was: Namespaces in functions vs classes)

2011-04-19 Thread Ben Finney
Rhodri James rho...@wildebst.demon.co.uk writes: Language abuse: it's not just Python. A donation of just $5 will keep a programmer in prepositions for a month. $50 will supply enough articles to keep a small company understandable for over a year. With your generous help, we can beat this

Re: [OT] Piling of prepositions (was: Namespaces in functions vs classes)

2011-04-19 Thread Dave Angel
On 01/-10/-28163 02:59 PM, Ben Finney wrote: Rhodri Jamesrho...@wildebst.demon.co.uk writes: Language abuse: it's not just Python. A donation of just $5 will keep a programmer in prepositions for a month. $50 will supply enough articles to keep a small company understandable for over a year.

Re: [OT] Piling of prepositions (was: Namespaces in functions vs classes)

2011-04-19 Thread geremy condra
On Tue, Apr 19, 2011 at 7:49 PM, Dave Angel da...@ieee.org wrote: On 01/-10/-28163 02:59 PM, Ben Finney wrote: Rhodri Jamesrho...@wildebst.demon.co.uk  writes: Language abuse: it's not just Python. A donation of just $5 will keep a programmer in prepositions for a month. $50 will supply

Namespaces in functions vs classes

2011-04-17 Thread Gerald Britton
I apologize if this has been answered before or if it is easy to find in the docs. (I couldn't find it but might have missed it) I'm trying to understand the differences between namespaces in class definitions vs. function definitions. Consider this function: def a(): ... foo = 'foo' ...

Re: Namespaces in functions vs classes

2011-04-17 Thread Chris Rebert
On Sun, Apr 17, 2011 at 12:30 PM, Gerald Britton gerald.brit...@gmail.com wrote: I apologize if this has been answered before or if it is easy to find in the docs. (I couldn't find it but might have missed it) I'm trying to understand the differences between namespaces in class definitions

Re: Namespaces in functions vs classes

2011-04-17 Thread Ethan Furman
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

Re: Namespaces in functions vs classes

2011-04-17 Thread Ethan Furman
Gerald Britton wrote: For my final attempt, I add the prefix a. to my use of foo class a(): ... foo = 'foo' ... def g(x): ... return a.foo ... The first parameter to any method in a class* is going to be the instance of that class, and is usually named 'self'. So your

Re: Namespaces in functions vs classes

2011-04-17 Thread Richard Thomas
On Apr 17, 8:56 pm, Chris Rebert c...@rebertia.com wrote: On Sun, Apr 17, 2011 at 12:30 PM, Gerald Britton gerald.brit...@gmail.com wrote: I apologize if this has been answered before or if it is easy to find in the docs. (I couldn't find it but might have missed it) I'm trying