new style class
Wildemar Wildenburger
lasses_weil at klapptsowieso.net
Fri Nov 2 07:44:10 EDT 2007
gert wrote:
> oops the code is like this but doesn't work
>
> class Test(object):
>
> def m1(self,v):
> return v
>
> def m2(v):
> return v
>
> if __name__ == '__main__':
> gert = Test()
> print gert.m1('1')
> print Test.m2('2')
>
Well, what do you think:
> In [9]: gert = Test()
>
> In [10]: print gert.m1('1')
> ....: print Test.m2('2')
> ....:
> 1
> ---------------------------------------------------------------------------
> <type 'exceptions.TypeError'> Traceback (most recent call last)
>
> /home/wildemar/<ipython console> in <module>()
>
> <type 'exceptions.TypeError'>: unbound method m2() must be called with Test instance as first argument (got str instance instead)
(Another hint: look at what m1 has that m2 lacks.)
/W
More information about the Python-list
mailing list