__slots__ and copy again: why does it work?
fortepianissimo
fortepianissimo at gmail.com
Mon Dec 26 21:43:00 EST 2005
More weird observations: the following code does not work until you
change the name of the member 'longer' to a one-char name, for example,
'j':
--- START ---
#!/usr/bin/env python
import copy
class Foo (object):
__slots__ = 'i'
class Bar (Foo):
__slots__ = 'longer'
#__slots__ = 'j'
b1 = Bar()
b1.longer = 22
#b1.j = 22
b2 = copy.copy(b1)
# doesn't work in Python 2.4.2
# BUT if 'longer' is changed to 'j' in the entire file, then it works!
print b2.longer
#print b2.j
--- END ---
I've tried different names and concluded that as long as I used one
character the code works. Anything longer than one character bombs.
Why?
More information about the Python-list
mailing list