Re: __init__ explanation please

2008-01-17 Thread Lie
On Jan 16, 5:34 am, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote: > > >From the base definition of a constructor: constructor is the creator > > of an object. In this case, __new__ is technically the constructor > > while __init__ is an initializer. > > > However, it is also to be noted that __init_

Re: __init__ explanation please

2008-01-15 Thread Steven D'Aprano
On Tue, 15 Jan 2008 14:02:43 -0800, Lie wrote: > I've been in this Python mailing list for a few days, and I've noticed > several things here: There are too many fundamentalist! > > Don't play stupid and all, don't be a fundamentalist. It might be true > that __init__ isn't a constructor and __ne

RE: __init__ explanation please

2008-01-15 Thread Reedick, Andrew
> -Original Message- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of Lie > Sent: Tuesday, January 15, 2008 5:03 PM > To: python-list@python.org > Subject: Re: __init__ explanation please > > I've been in this Python mailing list for

Re: __init__ explanation please

2008-01-15 Thread Lie
I've been in this Python mailing list for a few days, and I've noticed several things here: There are too many fundamentalist! Don't play stupid and all, don't be a fundamentalist. It might be true that __init__ isn't a constructor and __new__ might be the constructor (some people even claimed __n

Re: __init__ explanation please

2008-01-15 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > So while it's true that __init__ is the closest equivalent to what > C++ and Java (and possibly a couple "other languages") call a > constructor, it doesn't imply that you should refer to it as "the > constructor". As Neil Cerutti points out, there

Re: __init__ explanation please

2008-01-15 Thread Bruno Desthuilliers
Hrvoje Niksic a écrit : > Ben Finney <[EMAIL PROTECTED]> writes: > >> Hrvoje Niksic <[EMAIL PROTECTED]> writes: >> >>> Wildemar Wildenburger <[EMAIL PROTECTED]> writes: __init__() /initializes/ an instance (automatically after creation). It is called, /after/ the instance has been constr

Re: __init__ explanation please

2008-01-14 Thread Ben Finney
Hrvoje Niksic <[EMAIL PROTECTED]> writes: > Ben Finney <[EMAIL PROTECTED]> writes: > > > Hrvoje Niksic <[EMAIL PROTECTED]> writes: > >> __init__ *is* the closest equivalent to what other languages > >> would call a constructor. > > > > No. That would be '__new__', which actually constructs the >

Re: __init__ explanation please

2008-01-14 Thread Steven D'Aprano
On Tue, 15 Jan 2008 00:00:45 +0100, Hrvoje Niksic wrote: > Ben Finney <[EMAIL PROTECTED]> writes: > >> Hrvoje Niksic <[EMAIL PROTECTED]> writes: >> >>> Wildemar Wildenburger <[EMAIL PROTECTED]> writes: >>> > __init__() /initializes/ an instance (automatically after creation). >>> > It is called,

Re: __init__ explanation please

2008-01-14 Thread Hrvoje Niksic
Ben Finney <[EMAIL PROTECTED]> writes: > Hrvoje Niksic <[EMAIL PROTECTED]> writes: > >> Wildemar Wildenburger <[EMAIL PROTECTED]> writes: >> > __init__() /initializes/ an instance (automatically after >> > creation). It is called, /after/ the instance has been constructed >> >> I don't understand

Re: __init__ explanation please

2008-01-14 Thread Ben Finney
Hrvoje Niksic <[EMAIL PROTECTED]> writes: > Wildemar Wildenburger <[EMAIL PROTECTED]> writes: > > __init__() /initializes/ an instance (automatically after > > creation). It is called, /after/ the instance has been constructed > > I don't understand the purpose of this "correction". After all, >

Re: __init__ explanation please

2008-01-14 Thread Steven D'Aprano
On Mon, 14 Jan 2008 22:18:44 +1100, Ben Finney wrote: > What one is "in reality" calling is the '__new__' method of the Person > class. That function, in turn, is creating a new Person instance, and > calling the '__init__' method of the newly-created instance. Finally, > the '__new__' method retu

Re: __init__ explanation please

2008-01-14 Thread Hrvoje Niksic
"Reedick, Andrew" <[EMAIL PROTECTED]> writes: >> Only if by "construct" you mean "allocate". __init__ starts out >> with an empty object and brings it to a valid state, therefore >> "constructing" the object you end up with. That operation is >> exactly what other languages call a constructor. >

Re: __init__ explanation please

2008-01-14 Thread Neil Cerutti
On Jan 14, 2008 12:08 PM, Reedick, Andrew <[EMAIL PROTECTED]> wrote: > > -Original Message- > > From: [EMAIL PROTECTED] [mailto:python- > > [EMAIL PROTECTED] On Behalf Of Hrvoje Niksic > > Sent: Monday, January 14, 2008 11:29 AM > > Only if by "construct" you mean "allocate". __init__ star

RE: __init__ explanation please

2008-01-14 Thread Reedick, Andrew
> -Original Message- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of Hrvoje Niksic > Sent: Monday, January 14, 2008 11:29 AM > To: python-list@python.org > Subject: Re: __init__ explanation please > > Mel <[EMAIL PROTECTED]> writ

Re: __init__ explanation please

2008-01-14 Thread Hrvoje Niksic
Mel <[EMAIL PROTECTED]> writes: >> I don't understand the purpose of this "correction". After all, >> __init__ *is* the closest equivalent to what other languages would >> call a constructor. > > Nevertheless, __init__ doesn't construct anything. Only if by "construct" you mean "allocate". __

Re: __init__ explanation please

2008-01-14 Thread Mel
Hrvoje Niksic wrote: > Wildemar Wildenburger <[EMAIL PROTECTED]> writes: > >> Jeroen Ruigrok van der Werven wrote: >>> To restate it more correctly: __init__ is akin to a constructor. >>> >> No. See Hrvoje Niksic's reply (and Ben Finney's to which it was a >> reply). >> >> __init__() /initializes/

Re: __init__ explanation please

2008-01-14 Thread Hrvoje Niksic
Wildemar Wildenburger <[EMAIL PROTECTED]> writes: > Jeroen Ruigrok van der Werven wrote: >> To restate it more correctly: __init__ is akin to a constructor. >> > No. See Hrvoje Niksic's reply (and Ben Finney's to which it was a > reply). > > __init__() /initializes/ an instance (automatically afte

Re: __init__ explanation please

2008-01-14 Thread Wildemar Wildenburger
Jeroen Ruigrok van der Werven wrote: > To restate it more correctly: __init__ is akin to a constructor. > No. See Hrvoje Niksic's reply (and Ben Finney's to which it was a reply). __init__() /initializes/ an instance (automatically after creation). It is called, /after/ the instance has been con

Re: __init__ explanation please

2008-01-14 Thread Hrvoje Niksic
Ben Finney <[EMAIL PROTECTED]> writes: > What one is "in reality" calling is the '__new__' method of the Person > class. That function, in turn, is creating a new Person instance, and > calling the '__init__' method of the newly-created instance. Finally, > the '__new__' method returns that insta

Re: __init__ explanation please

2008-01-14 Thread Jeroen Ruigrok van der Werven
-On [20080113 14:03], Ben Finney ([EMAIL PROTECTED]) wrote: >That's getting the two of them confused. __new__ is a constructor, >__init__ is not. And there I just sent an email stating the wrong thing. I'll dig into it again, because I am really confusing something here (and jumping between 4 lan

Re: __init__ explanation please

2008-01-14 Thread Jeroen Ruigrok van der Werven
-On [20080113 13:36], Fredrik Lundh ([EMAIL PROTECTED]) wrote: >given that they do different things, I'm not sure it's that helpful to >describe them *both* as constructors. I am still behind in my learning. ;) To restate it more correctly: __init__ is akin to a constructor. I am not entirely s

Re: __init__ explanation please

2008-01-14 Thread Ben Finney
"A.T.Hofkamp" <[EMAIL PROTECTED]> writes: > while you think you are doing "Person('me', 'here', 31)", you are in > reality executing "Person.__init__(self, 'me', 'here', 31)", where > 'self' is refers to a shiny new, empty object created for you. This is misleading, and founders on many discrepan

Re: __init__ explanation please

2008-01-14 Thread A.T.Hofkamp
On 2008-01-13, Erik Lind <[EMAIL PROTECTED]> wrote: > I'm new to Python, and OOP. I've read most of Mark Lutz's book and more > online and can write simple modules, but I still don't get when __init__ > needs to be used as opposed to creating a class instance by assignment. For > some strange re

Re: __init__ explanation please

2008-01-13 Thread Ben Finney
Jeroen Ruigrok van der Werven <[EMAIL PROTECTED]> writes: > -On [20080113 01:41], Erik Lind ([EMAIL PROTECTED]) wrote: > >I'm new to Python, and OOP. I've read most of Mark Lutz's book and > >more online and can write simple modules, but I still don't get > >when __init__ needs to be used as oppos

Re: __init__ explanation please

2008-01-13 Thread Fredrik Lundh
Erik Lind wrote: > I'm new to Python, and OOP. I've read most of Mark Lutz's book and more > online and can write simple modules, but I still don't get when __init__ > needs to be used as opposed to creating a class instance by assignment. nothing is ever created by plain assignment in Python;

Re: __init__ explanation please

2008-01-13 Thread Fredrik Lundh
Jeroen Ruigrok van der Werven wrote: > I personally tend to see __init__ or __new__ as equivalent to what other > languages call a constructor. > > (And I am sure some people might disagree with that. ;)) given that they do different things, I'm not sure it's that helpful to describe them *both

Re: __init__ explanation please

2008-01-13 Thread Jeroen Ruigrok van der Werven
-On [20080113 01:41], Erik Lind ([EMAIL PROTECTED]) wrote: >I'm new to Python, and OOP. I've read most of Mark Lutz's book and more >online and can write simple modules, but I still don't get when __init__ >needs to be used as opposed to creating a class instance by assignment. I personally tend

Re: __init__ explanation please

2008-01-13 Thread Daniel Fetchinson
Please keep discussion on the list.. > > I'm not sure if I understand your question correctly but maybe this will > > help: > > > > If you want code to be run upon creating an instance of your class you > > would use __init__. Most common examples include setting attributes on > > the instance

Re: __init__ explanation please

2008-01-12 Thread Colin J. Williams
Erik Lind wrote: > I'm new to Python, and OOP. I've read most of Mark Lutz's book and more > online and can write simple modules, but I still don't get when __init__ > needs to be used as opposed to creating a class instance by assignment. For > some strange reason the literature seems to take t

Re: __init__ explanation please

2008-01-12 Thread Daniel Fetchinson
> I'm new to Python, and OOP. I've read most of Mark Lutz's book and more > online and can write simple modules, but I still don't get when __init__ > needs to be used as opposed to creating a class instance by assignment. For > some strange reason the literature seems to take this for granted. I'd

__init__ explanation please

2008-01-12 Thread Erik Lind
I'm new to Python, and OOP. I've read most of Mark Lutz's book and more online and can write simple modules, but I still don't get when __init__ needs to be used as opposed to creating a class instance by assignment. For some strange reason the literature seems to take this for granted. I'd app