Converting a string to a tuple

Fredrik Lundh fredrik at pythonware.com
Wed Apr 14 03:12:22 EDT 1999


> > 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).
> 
> No it isn't.

of course it is.  when used in Python's string representation,
which was what I was talking about.  please read the entire
message before following up on pieces of it.

> The problem arises because of the second evaluation.  Either use
> string.replace to double backslashes in the string, prefix the string
> with an "r", or don't use eval.

argh! if you have the string in source code, just remove the
outer quotes.  converting strings to tuples has never been
easier.  but I suspect Bruce was looking for something else,
and that he was tricked by Python's string syntax and repr.
it has happened to many good programmers before, as can
be seen in the c.l.py archives.

> I'd avoid eval...

why?  it's there, it works, and it can be used in a safe way,
as shown in earlier posts.  and converting strings to tuples
is kinda hard without it...

</F>





More information about the Python-list mailing list