Re: On Class namespaces, calling methods

2010-04-24 Thread Aahz
In article <4bd2e20...@dnews.tpgi.com.au>, Lie Ryan wrote: >On 04/24/10 06:07, Aahz wrote: >> In article <4bc120bd$0$8850$c3e8...@news.astraweb.com>, >> Steven D'Aprano wrote: >>> >>> I can only think of two circumstances where old-style classes are >>> *wrong*: if you use multiple inheritance

Re: On Class namespaces, calling methods

2010-04-24 Thread Lie Ryan
On 04/24/10 06:07, Aahz wrote: > In article <4bc120bd$0$8850$c3e8...@news.astraweb.com>, > Steven D'Aprano wrote: >> >> I can only think of two circumstances where old-style classes are >> *wrong*: if you use multiple inheritance with a diamond diagram ("...now >> you have THREE problems" *wink

Re: On Class namespaces, calling methods

2010-04-23 Thread Aahz
In article <4bc120bd$0$8850$c3e8...@news.astraweb.com>, Steven D'Aprano wrote: > >I can only think of two circumstances where old-style classes are >*wrong*: if you use multiple inheritance with a diamond diagram ("...now >you have THREE problems" *wink*), if you intend using descriptors such a

Re: On Class namespaces, calling methods

2010-04-11 Thread Duncan Booth
Steven D'Aprano wrote: > On Sat, 10 Apr 2010 16:35:29 +, Duncan Booth wrote: > >> Anyway, the moral is never, ever to use old-style classes in Python >> 2.x. You will get weird and unexpected results. > > That's a bit strong. They're only weird and unexpected if you're not > expecting them

Re: On Class namespaces, calling methods

2010-04-10 Thread Steven D'Aprano
On Sat, 10 Apr 2010 16:35:29 +, Duncan Booth wrote: > Anyway, the moral is never, ever to use old-style classes in Python 2.x. > You will get weird and unexpected results. That's a bit strong. They're only weird and unexpected if you're not expecting them and don't understand them. Why are

Re: On Class namespaces, calling methods

2010-04-10 Thread Duncan Booth
vsoler wrote: > On Apr 10, 4:46 pm, Duncan Booth wrote: >> vsoler wrote: >> > I get the following error message: >> >> >      TypeError: m() takes no arguments (1 given) >> >> Which version of Python are you using? Python 2.6 gives: >> >> TypeError: unbound method m() must be called with Uno i

Re: On Class namespaces, calling methods

2010-04-10 Thread Patrick Maupin
On Apr 10, 9:26 am, vsoler wrote: > class Uno: >     a=1 >     def m(): >         print "mouse" > ... > I cannot write >       Uno.m() By default (at least in Python 2.x), Python will pass any function which is accessed through getattr on class or instance (usually called a "method") an instan

Re: On Class namespaces, calling methods

2010-04-10 Thread vsoler
On Apr 10, 5:28 pm, Laszlo Nagy wrote: > > class Uno: > >     a=1 > >     def m(): > >         print "mouse" > > > Say that I have this "silly" class. > > > While I can then write > > >       print Uno.a > > > I cannot write > >       Uno.m() > > > I get the following error message: > > >      Typ

Re: On Class namespaces, calling methods

2010-04-10 Thread Laszlo Nagy
class Uno: a=1 def m(): print "mouse" Say that I have this "silly" class. While I can then write print Uno.a I cannot write Uno.m() I get the following error message: TypeError: m() takes no arguments (1 given) As a workaround, use this pattern: >>> cl

Re: On Class namespaces, calling methods

2010-04-10 Thread vsoler
On Apr 10, 4:46 pm, Duncan Booth wrote: > vsoler wrote: > > I get the following error message: > > >      TypeError: m() takes no arguments (1 given) > > > Since I have not created any instances of Uno, there is no self > > object, and I do not understand what object is supplied to the > > functi

Re: On Class namespaces, calling methods

2010-04-10 Thread vsoler
On Apr 10, 4:46 pm, Duncan Booth wrote: > vsoler wrote: > > I get the following error message: > > >      TypeError: m() takes no arguments (1 given) > > > Since I have not created any instances of Uno, there is no self > > object, and I do not understand what object is supplied to the > > functi

Re: On Class namespaces, calling methods

2010-04-10 Thread Alex Hall
On 4/10/10, vsoler wrote: > Still learning python, especially OOP. > > While testing classes, I sometimes think of them as "ordinary > containers" of values and functions (methods). That is, values and > functions can be grouped together inside "namespaces" calles classes. > > class Uno: > a=1

Re: On Class namespaces, calling methods

2010-04-10 Thread Duncan Booth
vsoler wrote: > I get the following error message: > > TypeError: m() takes no arguments (1 given) > > Since I have not created any instances of Uno, there is no self > object, and I do not understand what object is supplied to the > function call. > > Could anybody explain what argument