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
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
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
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
> 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
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.
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(
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
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