From: fredrik at pythonware.com (Fredrik Lundh)
Date: Wed, 14 Apr 1999 07:12:22 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> <008f01be85b8$a5be9580$f29b12c2@pythonware.com> <m2emlnn6fj.fsf@mycroft.actrix.gen.nz>
Message-ID: <040801be8646$823310d0$f29b12c2@pythonware.com>
Content-Length: 1064
X-UID: 1225                                                  

> > 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>





