Python instances

Bengt Richter bokr at oz.net
Wed Apr 20 04:45:18 EDT 2005


On 20 Apr 2005 00:44:53 -0700, henrikpierrou at hotmail.com wrote:

>Guess i shouldn't think of the __init__(self) function as a constructor
>then.
>Thanks.
Depends on what you think when you think "constructor" ;-)
Read about both __new__ and __init__. The former is always
necessary to create an object, and __init__ may take parameters to
define intial state from its parameters, but __new__ does the whole
job for immutables. I.e., "constructor" translates to combination of
both if both are present, but __new__ must be always be there and
come first. In general there are default methods inherited from
object and/or type, the most primitive classes, so you don't have
to define them except to customize for your purposes.
At least, that's the way I think of it ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list