Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '"if': 0.04; 'constructor': 0.07; 'underscores': 0.09; 'def': 0.15; 'class,': 0.15; 'from:addr:xs4all.nl': 0.16; 'message-id:@xs4all.nl': 0.16; 'received:194.109': 0.16; 'received:194.109.24': 0.16; 'received:xs4all.nl': 0.16; 'subject:PROBLEM': 0.16; 'x-mailer:apple mail (2.1084)': 0.16; 'wrote:': 0.16; 'say,': 0.19; 'badly': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'sep': 0.23; 'object,': 0.24; 'hey': 0.26; 'function': 0.27; 'problem': 0.28; 'print': 0.29; 'class': 0.30; 'does': 0.32; 'it.': 0.33; 'to:addr:python-list': 0.33; 'object': 0.35; 'charset :us-ascii': 0.36; 'but': 0.37; 'something': 0.37; 'two': 0.37; 'think': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'received:192': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'chosen': 0.40; 'your': 0.61; 'header:Message-Id:1': 0.61; 'greetings,': 0.66; 'subject:!': 0.67; 'derive': 0.84; 'distinguish': 0.84; 'things:': 0.91 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1084) Subject: Re: Constructors...BIIIIG PROBLEM! From: Michiel Overtoom In-Reply-To: Date: Thu, 1 Sep 2011 10:00:27 +0200 Content-Transfer-Encoding: quoted-printable References: To: PYTHON X-Mailer: Apple Mail (2.1084) X-Virus-Scanned: by XS4ALL Virus Scanner X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314864664 news.xs4all.nl 2402 [2001:888:2000:d::a6]:55348 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12552 On Sep 1, 2011, at 09:48, Amogh M S wrote: > Hey guys...=20 > 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 >=20 > class S: > def _init_(self, name=3DNone): > self.name =3D name > s =3D S("MyName") Two things: Derive your class from object, and the constructor function = should be '__init__', that is, with *two* underscores before and after = it. Are you reading a book or tutorial which does use a badly chosen = font which doesn't distinguish two consecutive underscores well? class S(object): def __init__(self, name=3DNone): self.name =3D name s =3D S("MyName") print s.name Greetings, --=20 "If you don't know, the thing to do is not to get scared, but to learn." = - Ayn Rand =20