Re: array of class / code optimization

2007-01-04 Thread Bruno Desthuilliers
mm a écrit : > > Yes, it was the (), equivalent to thiks like new() create new object > from class xy. Yeps. In Python there's no 'new' operator. Instead, classes are themselves 'callable' objects, acting as instance factory. It's very handy since it let's you replace a class with a factory fu

Re: array of class

2007-01-04 Thread Bruno Desthuilliers
Podi a écrit : >>>Or more compactly: >>> >>>words = [Word(w) for w in 'this is probably what you want'.split()] >>>print words >> >>I didn't want to introduce yet some more "confusing" stuff !-) > > > Indeed, the for loop is perfectly fine and totally readable. Let's save > the "confusing stuff"

Re: array of class / code optimization

2007-01-03 Thread hg
Neil Cerutti wrote: > On 2007-01-03, Jussi Salmela <[EMAIL PROTECTED]> wrote: >> hg kirjoitti: >>> mm wrote: >>> Yes, it was the (), equivalent to thiks like new() create new object from class xy. > s1.append(Word) s1.append(Word()) But I was looking for a "struct"

Re: array of class / code optimization

2007-01-03 Thread Bjoern Schliessmann
mm wrote: > But I was looking for a "struct" equivalent like in c/c++. > And/or "union". I can't find it. class Honk(object): pass test = Honk() test.spam = 4 test.eggs = "Yum" Is it this what you're looking for? > Maybe you know a source (URL) "Python for c/c++ programmers" or > things li

Re: array of class / code optimization

2007-01-03 Thread Neil Cerutti
On 2007-01-03, Jussi Salmela <[EMAIL PROTECTED]> wrote: > hg kirjoitti: >> mm wrote: >> >>> Yes, it was the (), equivalent to thiks like new() create new object >>> from class xy. s1.append(Word) >>> s1.append(Word()) >>> >>> But I was looking for a "struct" equivalent like in c/c++. >>> An

Re: array of class / code optimization

2007-01-03 Thread Jussi Salmela
hg kirjoitti: > mm wrote: > >> Yes, it was the (), equivalent to thiks like new() create new object >> from class xy. >>> s1.append(Word) >> s1.append(Word()) >> >> But I was looking for a "struct" equivalent like in c/c++. >> And/or "union". I can't find it. >> >> Maybe you know a source (URL)

Re: array of class / code optimization

2007-01-03 Thread hg
mm wrote: > > Yes, it was the (), equivalent to thiks like new() create new object > from class xy. >> s1.append(Word) > s1.append(Word()) > > But I was looking for a "struct" equivalent like in c/c++. > And/or "union". I can't find it. > > Maybe you know a source (URL) "Python for c/c++ prog

Re: array of class / code optimization

2007-01-03 Thread mm
Yes, it was the (), equivalent to thiks like new() create new object from class xy. > s1.append(Word) s1.append(Word()) But I was looking for a "struct" equivalent like in c/c++. And/or "union". I can't find it. Maybe you know a source (URL) "Python for c/c++ programmers" or things like that

Re: array of class

2007-01-02 Thread Podi
> > Or more compactly: > > > > words = [Word(w) for w in 'this is probably what you want'.split()] > > print words > > I didn't want to introduce yet some more "confusing" stuff !-) Indeed, the for loop is perfectly fine and totally readable. Let's save the "confusing stuff" to the Perl folks. -

Re: array of class

2007-01-02 Thread Bruno Desthuilliers
George Sakkis a écrit : > Bruno Desthuilliers wrote: > (snip) >>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 I didn'

Re: array of class

2007-01-02 Thread George Sakkis
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 "" % (self._word, id(self)) > > > words = [] > for w in ['this', 'is', 'probably', 'what

Re: array of class

2007-01-02 Thread Carl Banks
mm wrote: > 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="Th

Re: array of class

2007-01-02 Thread Bruno Desthuilliers
mm a écrit : > > How can I do a array of class? s/array/list/ > s1=[] ## this array should hold classes > > ## class definition > class Word: > word="" > > > ## empty words... INIT > for i in range(100): ## 0..99 > s1.append(Wort) I guess

Re: array of class

2007-01-02 Thread hg
mm wrote: > > 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].wo

array of class

2007-01-02 Thread mm
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