How to convert an object ref to string and the reverse

Ivan idivanov at hotmail.com
Thu Jun 21 11:25:05 EDT 2001


Hello, 
this is a basic question:
how is it possible to convert an instance
to string and how to do the reverse - convert the
resulting string in a valid object reference.
Example:

Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> class C:
...     def __init__(self):
...             self.msg = "hello"
...     def show(self):
...             print self.msg
...
>>> c_i = C()
>>> c_i.show()
hello
>>> c_i
<__main__.C instance at 007DE0FC>
>>> 
>>> d = <__main__.C instance at 007DE0FC>  <====??? How to do this?
  File "<stdin>", line 1
    d = <__main__.C instance at 007DE0FC>
        ^
SyntaxError: invalid syntax
>>> d.show()



More information about the Python-list mailing list