backslashes and strings

Steve Holden sholden at holdenweb.com
Tue Apr 24 14:51:07 EDT 2001


"Harald Kirsch" <kirschh at lionbioscience.com> wrote in message
news:yv2bspmba7b.fsf at lionsp093.lion-ag.de...
>
> Do I understand this correctly?
>
> >>> x='\\\\s'
> >>> x
> '\\\\s'
> >>> len(x)
> 3
>
> After assignment x contains a string with 3 characters, in particular
> 2 backslashes and an `s'. Typing x and <RETURN> gives me a
> representation of the value of x in a way that it could be parsed
> again into the true value of x. Right?
>
> Now continuing the example:
>
> >>> eval('"'+x+'"')
> '\\s'
> >>> print eval('"'+x+'"')
> \s
> >>> print len(eval('"'+x+'"'))
> 2
>
> This, in effect, runs the expression "\\s" which internally denotes a
> string with two characters, namely a backslash and an `s'.
>
Far more correctly than many, I should say.

regards
 STeve





More information about the Python-list mailing list