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
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"
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"
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
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
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)
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
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
> > 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.
-
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'
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
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
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
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
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
15 matches
Mail list logo