Python Reflection and Type Conversion
that would be best:
type(foo)(bar)
Use foo.__class__
to get the type of foo
. Then call it to convert bar to the type of foo:
def conv(foo, bar) :
return foo.__class__(bar)
Of course, this only works if the type of foo
has a constructor that knows how to convert bar.