On 11/10/2012 09:29 PM, Terry Reedy wrote:
On 11/10/2012 2:33 PM, Jennie wrote:
I propose three solutions. The first one:
>>> class Point:
... def __init__(self, x=0, y=0):
... self.x = x
... self.y = y
... def __sub__(self, other):
... return Poi
other):
... return Point(self.x - other.x, self.y - other.y)
...
>>> def distance(self, point=Point()):
... return math.sqrt((self - point).x ** 2 + (self - point).y ** 2)
...
>>> p = Point()
>>> p.distance(Point(3, 4))
5.0
Is there a better solution?
--
Jennie
--
http://mail.python.org/mailman/listinfo/python-list
On 10/20/2012 11:43 AM, Peter Otten wrote:
In Python 3 the way to specify the metaclass has changed:
class FooType(type):
... def __dir__(self): return ["python"]
...
class Foo(metaclass=FooType):
... pass
...
dir(Foo)
['python']
Thanks! :)
--
Jennie
--
ht
Peter, thanks for your answer, but it does not work (Python 3.3):
>>> class Foo:
... class __metaclass__(type):
... def __dir__(self): return ["python"]
...
>>> dir(Foo)
['__class__', '__delattr__', '__dict__', '__dir__', ...]
Regards,
--
Jennie
--
http://mail.python.org/mailman/listinfo/python-list
od
... def __dir__(cls):
... return ['python']
...
>>> Foo.__dir__()
['python']
>>> dir(Foo)
['__class__', '__delattr__', '__dict__', ...]
Can someone tell me where is the problem? Thanks a lot in advance
--
Jennie
--
http://mail.python.org/mailman/listinfo/python-list