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):
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
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 module
class C2(C1):
File ./c1.py, line 8, in
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.
nitActually, in python it does make sense, with a caveat that you have
to provide the
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 module
class C2(C1):
File ./c1.py, line 8, in C2
f1()
NameError: name 'f1' is not defined
f1() is an
On Sat, May 8, 2010 at 4:50 PM, ben thomasstr...@gmail.com 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 module
class C2(C1):
File ./c1.py, line
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 module
class C2(C1):
File ./c1.py, line 8, in C2
f1()
NameError: name 'f1' is not defined
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.
On May 8, 7:05 pm, Chris Rebert c...@rebertia.com wrote:
On Sat, May 8, 2010 at 4:50 PM, ben thomasstr...@gmail.com 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