M. Kostas - 10 months ago 52
Python Question

# Initialize variable depending on another variables type

In Python 2.7 I want to intialize a variables type depending on another variable.

For example I want to do something like:

var_1 = type(var_2)


Is there a simple/fast way to do that?

var_1 = type(var_2)()

Note that if you're not sure whether the object has a non-default constructor, you cannot rely on the above, but you can use copy (you get a "non-empty" object.
import copy