constructing an object from another instance of the same class
Christoph Groth
cwg at falma.de
Fri Jun 18 18:55:02 EDT 2010
Bruno Desthuilliers <bruno.42.desthuilliers at websiteburo.invalid> writes:
> Anyway: the simplest solution here is to replace the call to your Base
> class with a call to a factory function. I'd probably go for something
> like (Q&D untested code and other usual warnings) :
>
> (...)
Yeah, that will do what I want.
My confusion arose from the expectation that there had to be some
mechanism to do the conversion automatically. But actually a simple
def bar(arg):
if not isinstance(arg, Base):
arg = Base(arg)
# Do something with arg.
is a simple and explicit solution of the problem.
Thanks
Christoph
More information about the Python-list
mailing list