Raw strings as input from File?

rzed rzantow at gmail.com
Tue Dec 1 20:22:46 EST 2009


utabintarbo <utabintarbo at gmail.com> wrote in
news:adc6c455-5616-471a-8b39-d7fdad2179e4 at m33g2000vbi.googlegroups.c
om: 

> I have a log file with full Windows paths on a line. eg:
> K:\A\B\C\10xx\somerandomfilename.ext->/a1/b1/c1/10xx
> \somerandomfilename.ext ; t9999xx; 11/23/2009 15:00:16 ;
> 1259006416 
> 
> As I try to pull in the line and process it, python changes the
> "\10" to a "\x08". This is before I can do anything with it. Is
> there a way to specify that incoming lines (say, when using
> .readlines() ) should be treated as raw strings?
> 
> TIA

Despite all the ragging you're getting, it is a pretty flakey thing 
that Python does in this context:
(from a python shell)
>>> x = '\1'
>>> x
'\x01'
>>> x = '\10'
>>> x
'\x08'

If you are pasting your string as a literal, then maybe it does the 
same. It still seems weird to me. I can accept that '\1' means x01, 
but \10 seems to be expanded to \010 and then translated from octal 
to get to x08. That's just strange. I'm sure it's documented 
somewhere, but it's not easy to search for.

Oh, and this:
>>> '\7'
'\x07'
>>> '\70'
'8'
... is realy odd.

-- 
rzed



More information about the Python-list mailing list