Re: embarrassing class question

2010-10-30 Thread Steven D'Aprano
On Sat, 30 Oct 2010 19:30:21 +1300, Gregory Ewing wrote: > (BTW, there are no function names that have a special meaning in a > module dict -- a module is not like a class.) Pity... it would be nice to have a __main__() function, or perhaps main(), that was automatically called when you call the

Re: embarrassing class question

2010-10-29 Thread Gregory Ewing
Paul Rudin wrote: Gregory Ewing writes: You can clean up dir() by defining __all__ as a list of names that you want to officially export. I'm not sure that's necessarily a good idea... when you're trying to figure out why something behaves in a certain way you want to check for the presence

Re: embarrassing class question

2010-10-29 Thread Lawrence D'Oliveiro
In message <8idvgaf21...@mid.individual.net>, Peter Pearson wrote: > Yes, module w imports x, and therefore w.x exists. Is that bad? No-one seems to have come out and said this yet (unless it was in one of those messages that no longer seem to be accessible on my ISP’s news server): Python has

Re: embarrassing class question

2010-10-29 Thread Paul Rudin
Gregory Ewing writes: > Brendan wrote: >> I use >> Python sporadically, and frequently use the dir command to learn or >> remind myself of class methods. > > You can clean up dir() by defining __all__ as a list of > names that you want to officially export. Other names will > still be there, but

Re: embarrassing class question

2010-10-29 Thread Gregory Ewing
Brendan wrote: I use Python sporadically, and frequently use the dir command to learn or remind myself of class methods. You can clean up dir() by defining __all__ as a list of names that you want to officially export. Other names will still be there, but they won't show up in the dir() listing

Re: embarrassing class question

2010-10-25 Thread Brendan
On Oct 22, 2:21 pm, Peter Pearson wrote: > On Fri, 22 Oct 2010 07:49:39 -0700 (PDT), Brendan wrote: > > [snip] > > > > > > > x.py > > class X(object): > >     pass > > > y.py > > import x > > class Y(x.X): > >     pass > > > z.py > > import x > > import y > > class ZX(x.X): > >     pass > > class

Re: embarrassing class question

2010-10-22 Thread Peter Pearson
On Fri, 22 Oct 2010 07:49:39 -0700 (PDT), Brendan wrote: [snip] > x.py > class X(object): > pass > > y.py > import x > class Y(x.X): > pass > > z.py > import x > import y > class ZX(x.X): > pass > class ZY(y.Y): > pass > > w.py > import x > import y > import z > class WX(x.X): >

Re: embarrassing class question

2010-10-22 Thread Brendan
On Oct 22, 9:16 am, Dave Angel wrote: > On 2:59 PM, Brendan wrote:> On Oct 21, 3:56 pm, Ethan > Furman  wrote: > >> > >> Because y.py has "from x import x" the x class from x.py is added to the > >> y.py namespace. > > >> ~Ethan~- Hide quoted text - > > >> - Show quoted text - > > So what is usu

Re: Re: embarrassing class question

2010-10-22 Thread Dave Angel
On 2:59 PM, Brendan wrote: On Oct 21, 3:56 pm, Ethan Furman wrote: Because y.py has "from x import x" the x class from x.py is added to the y.py namespace. ~Ethan~- Hide quoted text - - Show quoted text - So what is usually done to prevent this? (In my case not wanting class x added to th

Re: embarrassing class question

2010-10-22 Thread Brendan
On Oct 22, 5:02 am, Steven D'Aprano wrote: > On Thu, 21 Oct 2010 12:12:34 -0700, Brendan wrote: > >> Because y.py has "from x import x" the x class from x.py is added to > >> the y.py namespace. > > >> ~Ethan~- Hide quoted text - > > >> - Show quoted text - > > > So what is usually done to prevent

Re: embarrassing class question

2010-10-22 Thread Steven D'Aprano
On Thu, 21 Oct 2010 12:12:34 -0700, Brendan wrote: >> Because y.py has "from x import x" the x class from x.py is added to >> the y.py namespace. >> >> ~Ethan~- Hide quoted text - >> >> - Show quoted text - > > So what is usually done to prevent this? (In my case not wanting class x > added to th

Re: embarrassing class question

2010-10-21 Thread Robert Kern
On 10/21/10 2:12 PM, Brendan wrote: On Oct 21, 3:56 pm, Ethan Furman wrote: Jonas H. wrote: On 10/21/2010 08:09 PM, Brendan wrote: Two modules: x.py: class x(object): pass y.py: from x import x class y(x): pass Now from the python command line: import y dir(y) ['__builtins

Re: embarrassing class question

2010-10-21 Thread Carl Banks
On Oct 21, 11:53 am, Brendan wrote: > On Oct 21, 3:47 pm, Carl Banks wrote: > > On Oct 21, 11:09 am, Brendan wrote: > > > > Two modules: > > > x.py: > > > class x(object): > > >     pass > > > > y.py: > > > from x import x > > > class y(x): > > >     pass > > > > Now from the python command line

Re: embarrassing class question

2010-10-21 Thread Brendan
On Oct 21, 3:56 pm, Ethan Furman wrote: > Jonas H. wrote: > > On 10/21/2010 08:09 PM, Brendan wrote: > >> Two modules: > >> x.py: > >> class x(object): > >>      pass > > >> y.py: > >> from x import x > >> class y(x): > >>      pass > > >> Now from the python command line: > > import y > >

Re: embarrassing class question

2010-10-21 Thread Ian
On Oct 21, 12:53 pm, Brendan wrote: > So it must never make sense to put subclasses in separate modules? It doesn't matter to Python whether the subclass is in the same module or imported. Do it whichever way makes the most sense to you from a code organization perspective. -- http://mail.pytho

Re: embarrassing class question

2010-10-21 Thread Robert Kern
On 10/21/10 1:53 PM, Brendan wrote: On Oct 21, 3:47 pm, Carl Banks wrote: On Oct 21, 11:09 am, Brendan wrote: Two modules: x.py: class x(object): pass y.py: from x import x class y(x): pass Now from the python command line:>>> import y dir(y) ['__builtins__', '__doc_

Re: embarrassing class question

2010-10-21 Thread Chris Rebert
On Thu, Oct 21, 2010 at 11:53 AM, Brendan wrote: > On Oct 21, 3:47 pm, Carl Banks wrote: >> On Oct 21, 11:09 am, Brendan wrote: >> > Two modules: >> > x.py: >> > class x(object): >> >     pass >> >> > y.py: >> > from x import x >> > class y(x): >> >     pass >> >> > Now from the python command l

Re: embarrassing class question

2010-10-21 Thread Ethan Furman
Jonas H. wrote: On 10/21/2010 08:09 PM, Brendan wrote: Two modules: x.py: class x(object): pass y.py: from x import x class y(x): pass Now from the python command line: import y dir(y) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'x', 'y'] I do not understand

Re: embarrassing class question

2010-10-21 Thread Brendan
On Oct 21, 3:47 pm, Carl Banks wrote: > On Oct 21, 11:09 am, Brendan wrote: > > > > > > > Two modules: > > x.py: > > class x(object): > >     pass > > > y.py: > > from x import x > > class y(x): > >     pass > > > Now from the python command line:>>> import y > > >>> dir(y) > > > ['__builtins__',

Re: embarrassing class question

2010-10-21 Thread Carl Banks
On Oct 21, 11:09 am, Brendan wrote: > Two modules: > x.py: > class x(object): >     pass > > y.py: > from x import x > class y(x): >     pass > > Now from the python command line:>>> import y > >>> dir(y) > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > 'x', 'y'] > > I do n

Re: embarrassing class question

2010-10-21 Thread Jonas H.
On 10/21/2010 08:09 PM, Brendan wrote: Two modules: x.py: class x(object): pass y.py: from x import x class y(x): pass Now from the python command line: import y dir(y) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'x', 'y'] I do not understand why class 'x' sh

embarrassing class question

2010-10-21 Thread Brendan
Two modules: x.py: class x(object): pass y.py: from x import x class y(x): pass Now from the python command line: >>> import y >>> dir(y) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'x', 'y'] I do not understand why class 'x' shows up here. -- http://mail.python.o