__slots__ and copy again: why does it work?
fortepianissimo
fortepianissimo at gmail.com
Mon Dec 26 23:55:01 EST 2005
To be complete, the first code snippet, when modified as follows, works
fine in Python 2.4.2:
--- START ---
#!/usr/bin/env python
import copy
class Foo (object):
__slots__ = ('i', )
def __init__ (self):
self.i = 10
class Bar (Foo):
__slots__ = ('j', )
def __init__ (self):
super(Bar, self).__init__()
self.j = 20
f1 = Foo()
f2 = copy.copy(f1)
print f2.i # works
b1 = Bar()
b2 = copy.copy(b1)
print b2.j # works
print b2.i # works
--- END ---
The last line didn't work last time because b2.i was never initialized.
More information about the Python-list
mailing list