On 06/18/2013 09:41 PM, Jim Mooney wrote:
Is there a way to unstring something? That is str(object) will give me
a string, but what if I want the original object back, for some
purpose, without a lot of foofaraw?


In general, definitely not. A class can define just about anything in its __str__() method, though it'd be polite for it to return a str. But there's no promise that you can do anything in particular to the str to even recover the type of the original object, never mind the value.

For example, in Python 3.3

>>> class Bar:
...     def __str__(self):
...         return "42"
...
>>> x = Bar()
>>> str(x)
'42'
>>> str(42)
'42'

--
DaveA
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to