In Python, if I have an object, say x, then how do I create a new object y so that x and y are of the same class?
In Java, the code I want would look something like this:
Object y = x.getClass().newInstance();
In Python, if I have an object, say x, then how do I create a new object y so that x and y are of the same class?
In Java, the code I want would look something like this:
Object y = x.getClass().newInstance();
You could probably do something like:
y = x.__class__()
or
y = type(x)() #New style classes only
And, if you're wondering how to make a new style class, all you need to do is inherit from object (or use python 3.x)
metaclasses are concerned, I don't use those either, so I can't help with that one. It's good to know where my solution might fail though. Thanks for pointing that out too.__init__ recieves no arguments (other than the obligatory self). I would assume you would have the same problem in Java?