__slots__ and copy again: why does it work?
fortepianissimo
fortepianissimo at gmail.com
Mon Dec 26 17:42:04 EST 2005
I should've mentioned this was tested on Python 2.4.2.
fortepianissimo wrote:
> I remember from painful experience that copy.copy() won't really copy
> __slots__ members. But I have trouble explaning why the following code
> works:
>
> --- 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):
> self.j = 20
>
>
> f1 = Foo()
> f2 = copy.copy(f1)
>
> print f2.i # why does it work?
>
>
> b1 = Bar()
> b2 = copy.copy(b1)
>
> print b2.j # why does it work?
> print b2.i # doesn't work, as expected
>
> --- END---
>
>
> Any insight is welcome!
More information about the Python-list
mailing list