Re: accessing superclass methods from subclass

2010-05-12 Thread Bruno Desthuilliers
Chris Rebert a écrit : (snip) Here is how I would rewrite your example: class Shape(object): def __init__(self, x=0, y=0): self.x = x self.y = y @property def location(self): return (self.x, self.y) @location.setter def location(self, val): se

Re: accessing superclass methods from subclass

2010-05-10 Thread Jean-Michel Pichavant
ben wrote: Ok, thanks for the info. What would be a better way to do this? What I'm trying to do is treat things in a reasonable OOP manner (all fairly new to me, esp. in Python). Here's a made-up example with a little more context. Let's say you're making a drawing program that can draw vari

Re: accessing superclass methods from subclass

2010-05-09 Thread Lie Ryan
On 05/09/10 10:05, Chris Rebert wrote: > Additionally, it makes no sense to call an *instance* method such as > f1() in a class context. Or in Java-speak: you can't call a non-static > method in a static context. Actually, in python it does make sense, with a caveat that you have to provide the in

Re: accessing superclass methods from subclass

2010-05-09 Thread TFH
On Sat, 08 May 2010 16:50:11 -0700, ben wrote: > Why doesn't this work: > > class C1: > def f1(self): > print("f1") > > class C2(C1): > f1() > > > It throws this error: > > Traceback (most recent call last): > File "./c1.py", line 7, in > class C2(C1): > File "./c1.py

Re: accessing superclass methods from subclass

2010-05-08 Thread Chris Rebert
> On May 8, 7:05 pm, Chris Rebert wrote: >> On Sat, May 8, 2010 at 4:50 PM, ben wrote: >> > Why doesn't this work: >> >> > class C1: >> >    def f1(self): >> >        print("f1") >> >> > class C2(C1): >> >    f1() >> >> > It throws this error: >> >> > Traceback (most recent call last): >> >  File

Re: accessing superclass methods from subclass

2010-05-08 Thread ben
Ok, thanks for the info. What would be a better way to do this? What I'm trying to do is treat things in a reasonable OOP manner (all fairly new to me, esp. in Python). Here's a made-up example with a little more context. Let's say you're making a drawing program that can draw various shapes.

Re: accessing superclass methods from subclass

2010-05-08 Thread MRAB
ben wrote: Why doesn't this work: class C1: def f1(self): print("f1") class C2(C1): f1() It throws this error: Traceback (most recent call last): File "./c1.py", line 7, in class C2(C1): File "./c1.py", line 8, in C2 f1() NameError: name 'f1' is not defined f1(

Re: accessing superclass methods from subclass

2010-05-08 Thread Chris Rebert
On Sat, May 8, 2010 at 4:50 PM, ben wrote: > Why doesn't this work: > > class C1: >    def f1(self): >        print("f1") > > class C2(C1): >    f1() > > > It throws this error: > > Traceback (most recent call last): >  File "./c1.py", line 7, in >    class C2(C1): >  File "./c1.py", line 8, in C

accessing superclass methods from subclass

2010-05-08 Thread ben
Why doesn't this work: class C1: def f1(self): print("f1") class C2(C1): f1() It throws this error: Traceback (most recent call last): File "./c1.py", line 7, in class C2(C1): File "./c1.py", line 8, in C2 f1() NameError: name 'f1' is not defined f1() is an attri