Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12619

Re: Constructors...BIIIIG PROBLEM!

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: Constructors...BIIIIG PROBLEM!
Date 2011-09-01 22:19 -0700
Organization > Bestiaria Support Staff <
References <CABWGKeW6sw2GJghQRbPcUA7_EO2V7SX5iJH0Pz0u513wX9TPNw@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.689.1314941709.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, 1 Sep 2011 13:18:52 +0530, Amogh M S <msamogh@gmail.com>
declaimed the following in gmane.comp.python.general:

> Hey guys...
> I think we have a problem with my _init_ method and the constructor
> When I create a class and its _init_ method and try to create an object of
> it outside the class,
> Say, something like
> 
> class S:
>    def _init_(self, name=None):
>        self.name = name
> s = S("MyName")
> 
> It says that the constructor takes no arguments!! I have to explicitly call
> the _init_ method which, I think is not the right way of doing things...
> Could you tell me if that is what is supposed to happen or is something
> wrong with my code?

	Besides the fact that the "constructor" is __new__(), and __init__()
is an initializer of the constructed object (rarely does one really need
to supply __new__() )... there is a difference from __init__() and
_init_()... The latter is just a "use at your own risk, none public
convention" name.

	Double underscore at beginning and end are Python special names.
Double underscore at beginning is a Python mangled name. Single
underscore at beginning is a programmer convention for "internal use
only".

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Constructors...BIIIIG PROBLEM! Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-09-01 22:19 -0700

csiph-web