Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Jennie
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

Method default argument whose type is the class not yet defined

2012-11-10 Thread Jennie
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

Re: How to see the __name__ attribute of a class by using dir()

2012-10-20 Thread Jennie
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

Re: How to see the __name__ attribute of a class by using dir()

2012-10-20 Thread Jennie
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

How to see the __name__ attribute of a class by using dir()

2012-10-20 Thread Jennie
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