array of class
George Sakkis
george.sakkis at gmail.com
Tue Jan 2 17:30:53 EST 2007
Bruno Desthuilliers wrote:
> FWIW, I guess that what you want here may looks like this:
>
> class Word(object):
> def __init__(self, word=''):
> self._word = word
> def __repr__(self):
> return "<Word %s at %d>" % (self._word, id(self))
>
>
> words = []
> for w in ['this', 'is', 'probably', 'what', 'you', 'want']:
> words.append(Word(w))
> print words
Or more compactly:
words = [Word(w) for w in 'this is probably what you want'.split()]
print words
George
More information about the Python-list
mailing list