I'm trying to get reflection to work in Python. I'm used to it in java but am having trouble getting it to work in python. Here is basically the code I have.

c = myObject.__class__ # get the class of the object
newC = c.__new__(c) #create a new instance of c

This doesn't work however. http://www.network-theory.co.uk/docs/pylang/Basiccustomization.html It says that __new__ makes a new instance but the error I'm getting is:

Exception in thread "Thread-4" Traceback (innermost last):
  File "<string>", line 1, in ?
TypeError: class.__new__(X): X is not a type object (class)
Exception in thread "Thread-4" Traceback (innermost last):
  File "<string>", line 1, in ?
TypeError: class.__new__(X): X is not a type object (class)

X is not a type (class) in reference to class.__new__(X) compared to c.__new__(c) would translate to X.__new__(X) . Ya feel me?

HTH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.