Pickle Problem
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Thu Mar 15 11:21:39 EDT 2007
In <1173971633.305988.207530 at d57g2000hsg.googlegroups.com>, tonyr1988
wrote:
> if __name__=='__main__':
> x = DemoClass
> x.WriteToFile
In Python classes, functions and methods are first class objects. You
bind the `DemoClass` class object to the name `x`, you are *not* creating
an instance of `DemoClass`.
Then you access the attribute `WriteToFile` of the `DemoClass` class
object. But you don't do anything with it.
In [39]: class DemoClass(object): pass
....:
In [40]: x = DemoClass
In [41]: x
Out[41]: <class '__main__.DemoClass'>
In [42]: y = DemoClass()
In [43]: y
Out[43]: <__main__.DemoClass object at 0xb5a3fd4c>
In [44]: x()
Out[44]: <__main__.DemoClass object at 0xb5a3fc2c>
You have to call the class object and the method to see any effects.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list