From: fredrik at pythonware.com (Fredrik Lundh)
Date: Tue, 13 Apr 1999 14:19:18 GMT
Subject: Converting a string to a tuple
References: <01be8530$65bb7120$52037e81@saints> <14098.28727.245158.616727@buffalo.fnal.gov> <00f501be857f$ff636f40$f29b12c2@pythonware.com> <01be85b5$f7197c90$52037e81@saints>
Message-ID: <008f01be85b8$a5be9580$f29b12c2@pythonware.com>
X-UID: 1318                                                  

Bruce Huzyk wrote:
> I will now take this opportunity to revise my original post.
> I wish to convert a string to a tuple.
> My sample string should have been:
> s = '(1, "abc\\tef", 2)' 
> instead of:
> s = '(1, "abc\\def", 2)' 

if that's Python source code, your string
actually contains:

    (1, "abc\tef", 2)

since \\ is Python's string representation
for a single backslash (that is, \\ in the
source code becomes \ in the actual
string).

and \t is an alias for \011 (a tab).

try printing it (using print) to see what
I mean.

but I doubt that this is the real problem --
if you have these strings in Python source
code, you could as well use your editor
to remove the quotes, right?

so if you get the data from a file or any
other external source, the plain eval
solutions work as they should.  for
simple data types like this,

    v == eval(repr(v))

is always true.

</F>





