Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.109.133.83.MISMATCH!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'classes,': 0.05; 'subject:Python': 0.06; 'class,': 0.07; 'method.': 0.07; '__init__': 0.09; 'used.': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; '"in': 0.16; '"in': 0.16; 'called,': 0.16; 'executed.': 0.16; 'instantiated': 0.16; 'precedence': 0.16; 'subclass': 0.16; 'subject:Query': 0.16; '\xa0print': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'starts': 0.20; 'example': 0.22; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**1': 0.23; 'creating': 0.23; 'flows': 0.24; 'instance,': 0.24; 'question': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'that.': 0.31; '"': 0.31; 'class': 0.32; 'cases': 0.33; 'skip:_ 10': 0.34; 'created': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'described': 0.36; 'method': 0.36; 'example,': 0.37; 'skip:& 10': 0.38; 'either': 0.39; '8bit%:6': 0.40; 'remove': 0.60; 'worry': 0.60; 'skip:t 30': 0.61; 'first': 0.61; 'dont': 0.67; ',the': 0.84; "class's": 0.84; 'to:addr:yahoo.co.in': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=0CLDrhfCDf37vXeznBcb6RUCu4MfK4QEU2GBaWGeYN4=; b=dmqGN2WDXw/BlTcglmIWF0FdvLFJLZx13Fy5Un7c4oumQKU6l9BCthkY7U4w0NmkzR YdmlLaeAQTR0DnTRWwFqm0ZUvJuMNj3+ar0hEQjQRQXedNISfUsfLNZl5SFXwUnSpGFK mk7Q1M3Yf98c9ozZ7d5WYRtAIlPY/DwSB2QM1V899YKdAyUzSBxKYtVz/p50xOFA6v6X 8Oev9bAkh/jfbG6cl6Oje3ZOIcyLtHtvOqNgyNJ0D0P4NSDoFljVKQrysMN+F3EzwkF/ HWKubt5j0e1wRTHztNbeT8/nJ6q3Y3lJN3Mgbc9ydsNcdsnaAVlhqV66dasobMQeqv5T wZeA== MIME-Version: 1.0 X-Received: by 10.52.227.6 with SMTP id rw6mr8809103vdc.19.1377161193194; Thu, 22 Aug 2013 01:46:33 -0700 (PDT) In-Reply-To: <1377158037.22487.YahooMailBasic@web190503.mail.sg3.yahoo.com> References: <1377158037.22487.YahooMailBasic@web190503.mail.sg3.yahoo.com> Date: Thu, 22 Aug 2013 09:46:33 +0100 Subject: Re: Basic Python Query From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: chandan kumar Content-Type: multipart/alternative; boundary=089e01161660b80afd04e485535d Cc: python-list@python.org, Johannes Bauer X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 112 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377161201 news.xs4all.nl 15950 [2001:888:2000:d::a6]:37420 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52822 --089e01161660b80afd04e485535d Content-Type: text/plain; charset=ISO-8859-1 On 22 Aug 2013 08:58, "chandan kumar" wrote: > > Hi all, > > Sorry for not explaining question properly.Here Its not about threading and dont worry about any indentations.Please see below example > > class Call_Constructor(): > def __init__(self): > print "In __init__ " > > class Test_Constructor(Call_Constructor): > def method(self): > print " In Test_Constructor Class" > > ConstructInstance = Test_Constructor() > > When an instace is created for Test_Constructor class ,The code flows starts __init__ in Call_Constructor class.Whys is it like that. > > > class Call_Constructor(): > def __init__(self): > print "In __init__ " > > > class Test_Constructor(Call_Constructor): > def __init__(self): > print " In Test_Constructor Class" > > ConstructInstance = Test_Constructor() > > But for the above case Code flows starts from Test_Constructor(). > > Whats is the difference for both cases described above. > > Best Regards, > Chandan. When creating an instance, Python will call __init__. In the first example there was only an __init__ method in the base class, so that one was used. On the second example, there were __init__ methods on both classes, but since you instantiated the subclass, the subclass's __init__ method was executed. Subclass methods have precedence over base class methods. If you want the __init__ method of the base class in the second example to be called, you can either remove the subclass __init__ method or call super(TestConstructor, self).__init__() in that method. That will call the base class's __init__. --089e01161660b80afd04e485535d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


On 22 Aug 2013 08:58, "chandan kumar" <chandan_psr@yahoo.co.in> wrote:
>
> Hi all,
>
> Sorry for not explaining question properly.Here Its not about threadin= g and dont worry about any indentations.Please see below example
>
> class Call_Constructor():
> =A0 =A0 def __init__(self):
> =A0 =A0 =A0 =A0 print "In __init__ "
>
> class Test_Constructor(Call_Constructor):
> =A0 =A0 def method(self):
> =A0 =A0 =A0 =A0print " In Test_Constructor Class"
>
> =A0 ConstructInstance =3D Test_Constructor()
>
> When an instace is created for Test_Constructor class ,The code flows = starts __init__ in Call_Constructor class.Whys is it like that.
>
>
> class Call_Constructor():
> =A0 =A0 def __init__(self):
> =A0 =A0 =A0 =A0 print "In __init__ "
>
>
> class Test_Constructor(Call_Constructor):
> =A0 =A0 def =A0__init__(self):
> =A0 =A0 =A0 =A0print " In Test_Constructor Class"
>
> =A0 ConstructInstance =3D Test_Constructor()
>
> But for the above case Code flows starts from Test_Constructor().
>
> Whats is the difference for both cases described above.
>
> Best Regards,
> Chandan.

When creating an instance, Python will call __init__. In the= first example there was only an __init__ method in the base class, so that= one was used. On the second example, there were __init__ methods on both c= lasses, but since you instantiated the subclass, the subclass's __init_= _ method was executed.

Subclass methods have precedence over base class methods. If= you want the __init__ method of the base class in the second example to be= called, you can either remove the subclass __init__ method or call super(T= estConstructor, self).__init__() in that method. That will call the base cl= ass's __init__.

--089e01161660b80afd04e485535d--