New inited instance of class?

Samuel Kleiner sam at samuel-kleiners-computer.local
Sun Dec 7 05:05:00 CET 2003

Francis Avila wrote:
> Samuel Kleiner wrote in message ...
>>Is there a builtin way of making making another instance of your own
> You mean, from the inside (from one of the instance methods of the class)?


> def new(self, *args, **kargs):
>     return self.__class__(*args, **kargs)

This works. Thanks. 

>>I really expected type(self)(*args, **keywords) to work this way.
> Works for me.  What traceback does it give you?

Not for me. I really want to call it as the function itself, and


fails with

Traceback (most recent call last):
  File "<stdin>", line 139, in ?
  File "<stdin>", line 78, in __add__
TypeError: instance() takes at most 2 arguments (3 given)



does not

>>Currently i'm doing this:
>>[my code]
> That's ugly.


On an encouraging note, however, I found that throughout the source code,
extremely conservative coding practices and good error checking everywhere
means that our software does not crash when handling IPv6 addresses.
--Joe Loughry, Lockheed Martin Space and Strategic Missiles, RADIANT MERCURY

More information about the Python-list mailing list