from string to raw string
Dan Perl
danperl at rogers.com
Wed Dec 15 22:46:58 EST 2004
This is not what I meant. My posting was a judgement error. You are right
though that my intuition was leading me to something like this. However, I
didn't realize that it was not necessary for what I was doing. But this is
very educational too. It made me look up string decode, encode, and codecs
in the library reference and I found out more about them. I'm sure it's
going to be useful. Thanks!
Dan
"Scott David Daniels" <Scott.Daniels at Acm.Org> wrote in message
news:41c0b2bc at nntp0.pdx.net...
> Dan Perl wrote:
>> Is there a way to convert a regular string to a raw string so that one
>> could get from '\bblah' to r'\bblah' other than parsing the string and
>> modifying the escapes?
>
> Assuming you might mean something else, that something else might be:
>
> s = r'no_tab_\t_here'
> len(s.split()) == 1
> len(s.decode('string_escape').split()) == 2
> s = 'tab_\t_here'
> len(s.split()) == 2
> len(s.encode('string_escape').split()) == 1
>
> -Scott David Daniels
> Scott.Daniels at Acm.Org
More information about the Python-list
mailing list