Assume that we have a test()
class defined as below :
>>> class test():
pass
Normally when I run the below code I make Obj
as an object of my test()
class :
>>> obj=test()
>>>
>>> obj
<__main__.test object at 0x00000000031B2390>
>>> type(obj)
<class '__main__.test'>
>>>
As you see above obj
has two features. It has a value and a type.
In the below, I assign Obj
value as a string to another variable called var1
:
>>> var1='<__main__.test object at 0x00000000031B2390>'
>>>
>>> type(var1)
<class 'str'>
>>>
As you see above , obj1
and var1
are equal in value, but are different in type. And again, as you know we can change type of an object to string using str()
function as below :
>>> Obj=str(Obj)
>>> Obj
'<__main__.test object at 0x00000000031B2390>'
>>>
Now, I want to know if is there any way to reverse above function? I mean, Is there any way to make a string-type variable as a object?
I mean is there any way to make Var1
equal to Obj
?
In the other word, assume that I know <__main__.test object at 0x00000000031B2390>
is the value of an object of a class. But I don't know neither the name of the object nor the name of the class. Now I want to create another object of that class. Is there any way?