Instances?
Angel Asencio
asencio at mitre.org
Tue Jul 31 16:09:08 EDT 2001
Original class:
class Foo:
x = []
y = []
Code tested on IDLE:
>>> a = classTest.Foo()
>>> b = classTest.Foo()
>>> a.x.append(3)
>>> b.x
[3]
Then, chenged the class to:
class Foo:
def __init__(self):
self.x = []
self.y = []
And the new result was:
del(a)
>>> del(b)
>>> a = classTest.Foo()
>>> b = classTest.Foo()
>>> a.x.append(3)
>>> b.x
[]
>>> a.x
[3]
>>>
So, does not putting data attributes inside the __init__ would
make them the equivalent to class variables on smalltalk or
static variables in Java?
Thanks,
--
-Angel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20010731/2bfe3a6b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: asencio.vcf
Type: text/x-vcard
Size: 317 bytes
Desc: Card for Angel Asencio
URL: <http://mail.python.org/pipermail/python-list/attachments/20010731/2bfe3a6b/attachment.vcf>
More information about the Python-list
mailing list