array of class
mm
michael at mustun.ch
Tue Jan 2 13:42:44 EST 2007
How can I do a array of class?
s1=[] ## this array should hold classes
## class definition
class Word:
word=""
## empty words... INIT
for i in range(100): ## 0..99
s1.append(Wort)
s1[0].word="There"
s1[1].word="should"
s1[2].word="be"
s1[3].word="different"
s1[4].word="classes"
... but it's not.
print s1
------------
[<class __main__.Wort at 0x7ff1492c>,
<class __main__.Wort at 0x7ff1492c>,
<class __main__.Wort at 0x7ff1492c>,
<class __main__.Wort at 0x7ff1492c>,
<class __main__.Wort at 0x7ff1492c>,
<class __main__.Wort at 0x7ff1492c>,
........
-----------
Here, this "classes" are all at the same position in memory. So there
are no different classes in the array.
So I access with s1[0], s1[1], s1[2], etc. always the same data.
Any idea?
--
Michael
More information about the Python-list
mailing list