Re: Inheritance Question

2012-10-18 Thread Jeff Jeffries
On Thu, Oct 18, 2012 at 10:51 AM, Dave Angel wrote: > On 10/18/2012 10:10 AM, Jeff Jeffries wrote: > > Hello everybody > > > > When I set "AttributeChanges" in my example, it sets the same value for > all > > other subclasses. Can someone help me with what the name of this behavior > > is (mutabl

Re: Inheritance Question

2012-10-18 Thread Dave Angel
On 10/18/2012 10:10 AM, Jeff Jeffries wrote: > Hello everybody > > When I set "AttributeChanges" in my example, it sets the same value for all > other subclasses. Can someone help me with what the name of this behavior > is (mutable class global?) ? I don't know any keywords... having > troubl

Re: Inheritance Question

2012-10-18 Thread Oscar Benjamin
On 18 October 2012 15:10, Jeff Jeffries wrote: > Hello everybody > > When I set "AttributeChanges" in my example, it sets the same value for all > other subclasses. Can someone help me with what the name of this behavior is > (mutable class global?) ? I don't know any keywords... having troub

Re: inheritance question...

2008-06-23 Thread Eric Brunel
Preamble: when posting a brand new question, you'd better not replying to an existing completely unrelated message. In most viewers, this will cause your message to appear in the thread for the original question and far less people will see it. So better create a brand new thread. On Fri, 2

Re: inheritance question...

2008-06-20 Thread Guilherme Polo
On Fri, Jun 20, 2008 at 6:19 PM, Hamish McKenzie <[EMAIL PROTECTED]> wrote: > > I have this class: > > class Vector(object): > TOL = 1e-5 > def __eq__( self, other, tolerance=TOL ): > print tolerance > > > shortened for clarity obviously. so I want to subclass this class like > s

Re: Inheritance question

2008-03-25 Thread Tzury Bar Yochay
Hi all, I would like to thank you all for all the suggestions. what I did was simply extending the super class data with data from its child using the id example, Foo.id = 1 is now = [1] and the FooSon does self.id.append(2) the system designer wanted inheritance+java and I wanted Python +Functi

Re: Inheritance question

2008-03-25 Thread castironpi
On Mar 25, 12:01 pm, Robert Bossy <[EMAIL PROTECTED]> wrote: > Hi, > > I'm not sure what you're trying to actually achieve, but it seems that > you want an identificator for classes, not for instances. In this case, > setting the id should be kept out of __init__ since it is an instance > initializ

Re: Inheritance question

2008-03-25 Thread Robert Bossy
Hi, I'm not sure what you're trying to actually achieve, but it seems that you want an identificator for classes, not for instances. In this case, setting the id should be kept out of __init__ since it is an instance initializer: make id static and thus getid() a classmethod. Furthermore, if yo

Re: Inheritance question

2008-03-25 Thread Gerard Flanagan
On Mar 25, 4:37 pm, Brian Lane <[EMAIL PROTECTED]> wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > > > Gerard Flanagan wrote: > > Use the child class when calling super: > > > -- > > class Foo(object): > > def __init__(self): > > self.id

Re: Inheritance question

2008-03-25 Thread Eric Brunel
On Tue, 25 Mar 2008 16:37:00 +0100, Brian Lane <[EMAIL PROTECTED]> wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Gerard Flanagan wrote: > >> Use the child class when calling super: >> >> -- >> class Foo(object): >> def __init__(self): >>

Re: Inheritance question

2008-03-25 Thread Diez B. Roggisch
Anthony wrote: > On Mar 25, 2:31 pm, Tzury Bar Yochay <[EMAIL PROTECTED]> wrote: >> I wish it was that simple but 'a = Foo().getid()' is actually creating >> a new instance of Foo whereas I want the data of the Foo instanced by >> __init__ of FooSon(). > > I don't think Foo.__init__(self) creates

Re: Inheritance question

2008-03-25 Thread Hrvoje Niksic
Brian Lane <[EMAIL PROTECTED]> writes: > Basically, you can't do what you are trying to do without using a > different variable, ...or abusing the __foo private identifier trick. -- http://mail.python.org/mailman/listinfo/python-list

Re: Inheritance question

2008-03-25 Thread Hrvoje Niksic
Tzury Bar Yochay <[EMAIL PROTECTED]> writes: > given two classes: > > class Foo(object): > def __init__(self): > self.id = 1 > > def getid(self): > return self.id > > class FooSon(Foo): > def __init__(self): > Foo.__init__(self) > self.id = 2 > > def

Re: Inheritance question

2008-03-25 Thread Brian Lane
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Gerard Flanagan wrote: > Use the child class when calling super: > > -- > class Foo(object): > def __init__(self): > self.id = 1 > > def getid(self): > return self.id > > class FooSon(Foo)

Re: Inheritance question

2008-03-25 Thread Anthony
On Mar 25, 2:31 pm, Tzury Bar Yochay <[EMAIL PROTECTED]> wrote: > I wish it was that simple but 'a = Foo().getid()' is actually creating > a new instance of Foo whereas I want the data of the Foo instanced by > __init__ of FooSon(). I don't think Foo.__init__(self) creates an instance of the Foo c

Re: Inheritance question

2008-03-25 Thread Gerard Flanagan
On Mar 25, 1:34 pm, Tzury Bar Yochay <[EMAIL PROTECTED]> wrote: > > Rather than use Foo.bar(), use this syntax to call methods of the > > super class: > > > super(ParentClass, self).method() > > Hi Jeff, > here is the nw version which cause an error > > class Foo(object): > def __init__(self):

Re: Inheritance question

2008-03-25 Thread Tzury Bar Yochay
On Mar 25, 4:03 pm, Anthony <[EMAIL PROTECTED]> wrote: > On Mar 25, 11:44 am, Tzury Bar Yochay <[EMAIL PROTECTED]> wrote: > > > While my intention is to get 1.2 I get 2.2 > > I would like to know what would be the right way to yield the expected > > results > > Is this what you want? > > class Foo(

Re: Inheritance question

2008-03-25 Thread Anthony
On Mar 25, 11:44 am, Tzury Bar Yochay <[EMAIL PROTECTED]> wrote: > While my intention is to get 1.2 I get 2.2 > I would like to know what would be the right way to yield the expected > results Is this what you want? class Foo(object): def __init__(self): self.id = 1 def getid(sel

Re: Inheritance question

2008-03-25 Thread Furkan Kuru
In the derived class init you set self.id to 2 so when you call getid method it just returns self.id which is now 2. you can use another variable name. On Tue, Mar 25, 2008 at 1:44 PM, Tzury Bar Yochay <[EMAIL PROTECTED]> wrote: > given two classes: > > class Foo(object): >def __init__(self):

Re: Inheritance question

2008-03-25 Thread Furkan Kuru
a = super(Foo, self).getid() should be a = super(FooSon, self).getid() On Tue, Mar 25, 2008 at 2:34 PM, Tzury Bar Yochay <[EMAIL PROTECTED]> wrote: > > Rather than use Foo.bar(), use this syntax to call methods of the > > super class: > > > > super(ParentClass, self).method() > > Hi Jeff, > here

Re: Inheritance question

2008-03-25 Thread Tzury Bar Yochay
> Rather than use Foo.bar(), use this syntax to call methods of the > super class: > > super(ParentClass, self).method() Hi Jeff, here is the nw version which cause an error class Foo(object): def __init__(self): self.id = 1 def getid(self): return self.id class FooSon(F

Re: Inheritance question

2008-03-25 Thread Tzury Bar Yochay
On Mar 25, 2:00 pm, John Machin <[EMAIL PROTECTED]> wrote: > On Mar 25, 10:44 pm, Tzury Bar Yochay <[EMAIL PROTECTED]> wrote: > > > > > given two classes: > > > class Foo(object): > >     def __init__(self): > >         self.id = 1 > > >     def getid(self): > >         return self.id > > > class F

Re: Inheritance question

2008-03-25 Thread John Machin
On Mar 25, 10:44 pm, Tzury Bar Yochay <[EMAIL PROTECTED]> wrote: > given two classes: > > class Foo(object): > def __init__(self): > self.id = 1 > > def getid(self): > return self.id > > class FooSon(Foo): > def __init__(self): > Foo.__init__(self) > self

Re: Inheritance question

2008-03-25 Thread Jeff
Rather than use Foo.bar(), use this syntax to call methods of the super class: super(ParentClass, self).method() -- http://mail.python.org/mailman/listinfo/python-list

Re: Inheritance Question

2006-11-11 Thread Carl Banks
Jackson wrote: > For a more "concrete" example: > > Suppose all the animals in the world have only 1 or 2 legs. > > class Legs(object) > def run(): pass > def walk(number_of_legs): > # lots of commands > # that do not depend on the > # number of legs but definitely > # have to d

Re: Inheritance Question

2006-11-11 Thread Frank Millman
Gabriel Genellina wrote: > At Saturday 11/11/2006 03:31, Frank Millman wrote: > > >Continuing your analogy of animals, assume a class A with a 'walk' > >method and an 'eat' method. > > > >Most animals walk the same way, but a few don't, so I create a subclass > >AW and override the walk method. >

Re: Inheritance Question

2006-11-10 Thread Gabriel Genellina
At Saturday 11/11/2006 03:31, Frank Millman wrote: Continuing your analogy of animals, assume a class A with a 'walk' method and an 'eat' method. Most animals walk the same way, but a few don't, so I create a subclass AW and override the walk method. Most animals eat the same way, but a few do

Re: Inheritance Question

2006-11-10 Thread Frank Millman
Jackson wrote: > I've got an inheritance question and was hoping brighter minds could > guide me. I am in the strange situation where some of the methods in a > subclass are actually more general than methods in a superclass. What > is the preferred way to handle such situations. My original th

Re: Inheritance Question

2006-11-10 Thread George Sakkis
Gabriel Genellina wrote: > If walking in general, have some common structure, you can put the > "sketch" on Legs and let the derived classes "fill the gaps". This is > known as "Template Method Pattern" - look for it. Or if you'd rather see a concrete example, here's how your toy example would lo

Re: Inheritance Question

2006-11-10 Thread Gabriel Genellina
At Friday 10/11/2006 21:13, Jackson wrote: I've got an inheritance question and was hoping brighter minds could guide me. I am in the strange situation where some of the methods in a subclass are actually more general than methods in a superclass. What is the preferred way to handle such situa