Re: [Tutor] super constructor usage

2017-03-31 Thread Alan Gauld via Tutor
On 30/03/17 21:08, Alan Gauld via Tutor wrote: > Of course, the __init__ methods are special in any way Should have said *not special* in any way... > But remember that not calling super potentially leaves > some attributes of your superclass uninitialized. By not > calling super you assume full

Re: [Tutor] super constructor usage

2017-03-31 Thread Mats Wichmann
On 03/30/2017 05:39 AM, Rafael Knuth wrote: I am trying to wrap my head around the super constructor. > > Is it possible to embed a super constructor into an if / elif > statement within the child class? > > if message == "string A": return X > elif: return Y > > How should I modify my code

Re: [Tutor] super constructor usage

2017-03-30 Thread Alan Gauld via Tutor
On 30/03/17 12:39, Rafael Knuth wrote: I am trying to wrap my head around the super constructor. > > Is it possible to embed a super constructor into an if / elif > statement within the child class? Of course, the __init__ methods are special in any way the normal coding mechanisms all work.

Re: [Tutor] super constructor usage

2017-03-30 Thread Rafael Knuth
>> > I am trying to wrap my head around the super constructor. Is it possible to embed a super constructor into an if / elif statement within the child class? if message == "string A": return X elif: return Y How should I modify my code below? (I couldn't solve that by myself) class A: def

Re: [Tutor] super constructor usage

2017-03-30 Thread Mats Wichmann
On 03/29/2017 08:33 AM, Rafael Knuth wrote: > class A: > def __init__(self, message): > self.message = message > print(message) > > I then modified the child class B like this: > > class B(A): > def __init__(self, message): > print("This is the message from your p

Re: [Tutor] super constructor usage

2017-03-30 Thread Mats Wichmann
On 03/29/2017 04:02 PM, Mats Wichmann wrote: > On 03/29/2017 08:33 AM, Rafael Knuth wrote: > >> class A: >> def __init__(self, message): >> self.message = message >> print(message) >> >> I then modified the child class B like this: >> >> class B(A): >> def __init__(self,

Re: [Tutor] super constructor usage

2017-03-29 Thread Steven D'Aprano
On Wed, Mar 29, 2017 at 10:32:52PM +0100, Alan Gauld via Tutor wrote: > On 29/03/17 15:33, Rafael Knuth wrote: > > I am trying to wrap my head around the super constructor. > > This is one of these cases where it matters whether you > are using Python v2 or v3. Use of super in v3 is much > easier

Re: [Tutor] super constructor usage

2017-03-29 Thread Steven D'Aprano
On Wed, Mar 29, 2017 at 04:33:20PM +0200, Rafael Knuth wrote: > I am trying to wrap my head around the super constructor. Simple example: > > class A: > def __init__(self): > print("world") > > class B(A): > def __init__(self): > print("hello") > super(B, self).__i

Re: [Tutor] super constructor usage

2017-03-29 Thread Alan Gauld via Tutor
On 29/03/17 15:33, Rafael Knuth wrote: > I am trying to wrap my head around the super constructor. This is one of these cases where it matters whether you are using Python v2 or v3. Use of super in v3 is much easier. It looks from your examples like you are using v2 but it would be good to confir

Re: [Tutor] super

2016-08-29 Thread Steven D'Aprano
On Mon, Aug 29, 2016 at 09:18:17PM +, monik...@netzero.net wrote: > Hi: > Why in super(Child,self).setVal(value) there is Child and self in super? Why > the repetition? Or should it say Parent instead of Child? > In my understanding it should say Parent2 instead of Child since it refers to >

Re: [Tutor] super and __init__ methods

2015-11-27 Thread Ben Finney
Sunil Tech writes: > Thanks I got it. Thanks for telling us! You should know that ‘super’ is a topic that confuses even quite experienced Python programmers. It is good to encounter this early, when you can learn about it. See the article “Python’s super() considered super!” https://rhettinger

Re: [Tutor] super and __init__ methods

2015-11-26 Thread Sunil Tech
Thanks I got it. class Cain(Adam): """docstring for Cain""" def __init__(self, age, *args): super(Cain, self).__init__(*args) self.age = age a = Adam('Eve') c = Cain(12, 'Eve') print a.name, c.age, c.name >>> Eve 12 Eve On Fri, Nov 27, 2015 at 12:44 PM, Sunil Tech wrot

Re: [Tutor] Super In tkinter class inheritance

2011-12-08 Thread Prasad, Ramit
>> class ChooseDestinationWindow(Frame): def __init__(self,master): >>super(ChooseDestinationWindow,self).__init_ _(master) >What exactly does this super method since I have seen it numerous >times before and as far as I can see it is not anything the user >created himself in the class? This has

Re: [Tutor] Super In tkinter class inheritance

2011-12-07 Thread Alan Gauld
On 07/12/11 17:01, George Nyoro wrote: I was observing the tkinter code under the topic "Creating arbitrary number of destinations. (GUI program)" in the previous email and saw this super thing: class ChooseDestinationWindow(Frame): def __init__(self,master): super(ChooseDestinationWindow,self).

Re: [Tutor] super() with Multiple Inheritance

2011-04-14 Thread Alan Gauld
"Steven D'Aprano" wrote No, because super returns whatever the superclass method returns. Which in init() is usually None. No, super returns a proxy object that encapsulates knowledge of the superclasses of the argument (usually "self", but not necessarily). >>> b = B() >>> s = super(B, b

Re: [Tutor] super() with Multiple Inheritance

2011-04-14 Thread Steven D'Aprano
Alan Gauld wrote: "James Thornton" wrote I found this issue -- I was setting setting self.s to the return value of super() and trying to use self.s in params(): ...but this won't work. No, because super returns whatever the superclass method returns. Which in init() is usually None. No

Re: [Tutor] super() with Multiple Inheritance

2011-04-14 Thread Steven D'Aprano
James, Your subject line is misleading: you ask about *multiple* inheritance, but the code you use is *single* inheritance: object -> Element -> Vertex -> Person -> User Multiple inheritance occurs when you have a class that inherits from two or more parent classes: cla

Re: [Tutor] super() with Multiple Inheritance

2011-04-14 Thread Alan Gauld
"James Thornton" wrote I found this issue -- I was setting setting self.s to the return value of super() and trying to use self.s in params(): ...but this won't work. No, because super returns whatever the superclass method returns. Which in init() is usually None. You have to use supe

Re: [Tutor] super() with Multiple Inheritance

2011-04-14 Thread James Thornton
I found this issue -- I was setting setting self.s to the return value of super() and trying to use self.s in params(): self.s = super(User,self) self.s.__init__(name,uri,email) def params(self): params = dict(name=self.name) params.update(self.s.params()) ...but this won't work.

Re: [Tutor] super() with Multiple Inheritance

2011-04-14 Thread Alan Gauld
"James Thornton" wrote Why does user.params() not return all the params up the inheritance chain? -- It's not including the params defined in Person() -- notice Vertex() does not have a params() method. class Element(object): def params(self): return dict(uuid=self.uuid, key=se

Re: [Tutor] super.__init__() arguments

2010-09-27 Thread Jojo Mwebaze
Thanks Guys! Works perfect cheers On Mon, Sep 27, 2010 at 1:01 PM, Wayne Werner wrote: > In addition it only works for new style classes. > > -wayne > > On 9/27/10, Lie Ryan wrote: > > On 09/27/10 09:45, Jojo Mwebaze wrote: > >> Hey Tutor, > >> > >> Seems a small issue but this has been p

Re: [Tutor] super.__init__() arguments

2010-09-27 Thread Jojo Mwebaze
Thanks Guys! Works perfect cheers On Mon, Sep 27, 2010 at 1:01 PM, Wayne Werner wrote: > In addition it only works for new style classes. > > -wayne > > On 9/27/10, Lie Ryan wrote: > > On 09/27/10 09:45, Jojo Mwebaze wrote: > >> Hey Tutor, > >> > >> Seems a small issue but this has been p

Re: [Tutor] super.__init__() arguments

2010-09-27 Thread Wayne Werner
In addition it only works for new style classes. -wayne On 9/27/10, Lie Ryan wrote: > On 09/27/10 09:45, Jojo Mwebaze wrote: >> Hey Tutor, >> >> Seems a small issue but this has been playing for a while now, what am i >> doing wrong here? >> > > super() without argument only works for Python 3.

Re: [Tutor] super.__init__() arguments

2010-09-27 Thread Lie Ryan
On 09/27/10 09:45, Jojo Mwebaze wrote: > Hey Tutor, > > Seems a small issue but this has been playing for a while now, what am i > doing wrong here? > super() without argument only works for Python 3. In Python 2.x, you have to pass to super your class name and your class instance, i.e.: Class

Re: [Tutor] super.__init__() arguments

2010-09-26 Thread Hugo Arts
On Mon, Sep 27, 2010 at 1:45 AM, Jojo Mwebaze wrote: > Hey Tutor, > Seems a small issue but this has been playing for a while now, what am i > doing wrong here? > Take an Example > Class Point: >    def __init__(self, x=0, y=0): >      self.x = x >      self.y = y > Class Circle(Point): >     def

Re: [Tutor] Super class

2009-09-25 Thread Alan Gauld
"Dave Angel" wrote It's an object oriented thing, and as such, "advanced programming." (IMHO) Yep, I'd agree. Although OOP is becoming more mainstream every year. In the way that using functions and proceduires used to e considered advanced concepts(compared to subroutines and GOTO) but are

Re: [Tutor] Super class

2009-09-25 Thread Dave Angel
Katt wrote: As I am a beginner I am constantly assimilating new python code and vocabulary associated with it. Could someone please explain to me what a super class is, its importance and what level of python programming it is(beginner,intermediate,advanced programming technique)? This would

Re: [Tutor] SUPER NEWB: basic search and replace

2006-09-01 Thread Alan Gauld
>I have a large volume of files to change so I need to > automate the search and replace. I'll be replacing > bits of text with other bits of text. This is working > for now but I'd like to know how a real programmer > would do it. A "real programmer" would use the right tool for the job, hence

Re: [Tutor] SUPER NEWB: basic search and replace

2006-09-01 Thread Kent Johnson
Lanky Nibs wrote: > I have a large volume of files to change so I need to > automate the search and replace. I'll be replacing > bits of text with other bits of text. This is working > for now but I'd like to know how a real programmer > would do it. The hard coded strings will eventually > come fr

Re: [Tutor] SUPER NEWB: basic search and replace

2006-09-01 Thread Dave Kuhlman
On Fri, Sep 01, 2006 at 09:26:36AM -0700, Lanky Nibs wrote: > I have a large volume of files to change so I need to > automate the search and replace. I'll be replacing > bits of text with other bits of text. This is working > for now but I'd like to know how a real programmer > would do it. The ha

Re: [Tutor] super() and inherited attributes?

2005-06-28 Thread jfouhy
Quoting Alan G <[EMAIL PROTECTED]>: > I don't know the direct answer but the more common way > of doing that in Python is not to use super() but just > call the inherited constructor directly: > > Parent.__init__(self,'I am a child') > > > SO if you just want to fix the itch use that, if you

Re: [Tutor] super() and inherited attributes?

2005-06-28 Thread Alan G
|class Parent(object): | def __init__(self, name="I am a parent"): | self.name = name | |class Child(Parent): | def __init__(self, number): | super(Parent, self).__init__("I am a child") | self.number = number | |# I would like it to produce the following: |>> c = Child(23) |>> c

Re: [Tutor] super() and inherited attributes?

2005-06-27 Thread Brian van den Broek
Marcus Goldfish said unto the world upon 28/06/2005 00:58: > Hi, > > The following example doesn't work as I would like-- the child > instance doesn't expose the attribute set in the parent. Can someone > point out what I am missing? > > Thanks, > Marcus > > > class Parent(object): >def __