How to convert an object ref to string and the reverse

Emile van Sebille emile at fenx.com
Thu Jun 21 18:29:38 CEST 2001


Do you mean like this?

>>> class C:
 def __init__(self):
  self.msg = "hello"
 def show(self):
  print self.msg


>>> c_i = C()
>>> c_i.show()
hello

>>> d = c_i
>>> d.show()
hello

>>> d
<__main__.C instance at 011674EC>
>>>

--

Emile van Sebille
emile at fenx.com

---------
"Ivan" <idivanov at hotmail.com> wrote in message
news:9dab6033.0106210725.935e7c4 at posting.google.com...
> 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