[Tutor] Converting a String to a Tuple

Carroll, Barry Barry.Carroll at psc.com
Fri Nov 4 22:30:38 CET 2005


My UDP client is receiving responses from the server, and now I need to
process them.  A typical response string looks like this:

    "(0, ''),some data from the test system"

The tuple represents the error code and message.  If the command had failed,
the response would look like this:

    "(-1, 'Error message from the test system')"

I need to extract the tuple from the rest of the response string.  I can do
this using eval, like so: 

    errtuple = eval(mytxt[:mytxt.find(')')+1])

Is there another, more specific method for transforming a sting into a

Thanks as always.  


More information about the Tutor mailing list