Carl Banks wrote:
> kelin,[EMAIL PROTECTED] wrote:
>> It says the __init__ is called immediately after an instance of the
>> class is created. What dose "immediately" mean?
>> And what is difference between the init method and the constructor in
>> Java?
>
> For all intents and purposes, __init__
Hi,
I've read all of this. And I am clear about it.
Thanks all.
Best Regards!
Gabriel Genellina wrote:
> At Tuesday 7/11/2006 21:47, Jia Lu wrote:
>
> > > In Python, the real constructor is called __new__, >
> > > Carl Banks
> >
> >But the code below won't invoke __new__:
>
> Is this a question, o
At Tuesday 7/11/2006 21:47, Jia Lu wrote:
> In Python, the real constructor is called __new__, >
> Carl Banks
But the code below won't invoke __new__:
Is this a question, or just for making things more and more confusing
to beginners?
class Test:
def __new__(self, value):
prin
> In Python, the real constructor is called __new__, >
> Carl Banks
But the code below won't invoke __new__:
[CODE]
class Test:
def __new__(self, value):
print "__new__",value
def __init__(self,value):
print "__init__",value
x = Test("testing")
[/CODE]
--
http://mail.p
kelin,[EMAIL PROTECTED] wrote:
> It says the __init__ is called immediately after an instance of the
> class is created. What dose "immediately" mean?
> And what is difference between the init method and the constructor in
> Java?
For all intents and purposes, __init__ is a constructor. It isn't
Steven D'Aprano ha escrit:
> Once the __new__ method creates the instance and returns, before anything
> else happens, the instance's __init__ method is called.
This only happens when the object created by __new__ isinstance of the
class invoked in the creation statement, that is:
s=MagicStr("l
On Tue, 07 Nov 2006 05:26:07 -0800, kelin,[EMAIL PROTECTED] wrote:
> Hi,
>
> Today I read the following sentences, but I can not understand what
> does the __init__ method of a class do?
Play around with this class and see if it helps:
class MagicStr(str):
"""Subclass of str with leadi
"kelin,[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Today I read the following sentences, but I can not understand what
> does the __init__ method of a class do?
> __init__ is called immediately after an instance of the class is
> created. It would be tempting but incorrect to call this the
> c
Hi,
Today I read the following sentences, but I can not understand what
does the __init__ method of a class do?
__init__ is called immediately after an instance of the class is
created. It would be tempting but incorrect to call this the
constructor of the class. It's tempting, because it looks li