Raw strings as input from File?

Jon Clements joncle at googlemail.com
Tue Nov 24 16:50:57 EST 2009


On Nov 24, 9:20 pm, utabintarbo <utabinta... at gmail.com> wrote:
> On Nov 24, 3:27 pm, MRAB <pyt... at mrabarnett.plus.com> wrote:
>
>
>
> > .readlines() doesn't change the "\10" in a file to "\x08" in the string
> > it returns.
>
> > Could you provide some code which shows your problem?
>
> Here is the code block I have so far:
> for l in open(CONTENTS, 'r').readlines():
>     f = os.path.splitext(os.path.split(l.split('->')[0]))[0]
>     if f in os.listdir(DIR1) and os.path.isdir(os.path.join(DIR1,f)):
>         shutil.rmtree(os.path.join(DIR1,f))
>         if f in os.listdir(DIR2) and os.path.isdir(os.path.join(DIR2,f)):
>                 shutil.rmtree(os.path.join(DIR2,f))
>
> I am trying to find dirs with the basename of the initial path less
> the extension in both DIR1 and DIR2
>
> A minimally obfuscated line from the log file:
> K:\sm\SMI\des\RS\Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz->/arch_m1/
> smi/des/RS/Pat/10DJ/121.D5-30\1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
> 11/24/2009 08:16:42 ; 1259068602
>
> What I get from the debugger/python shell:
> 'K:\\sm\\SMI\\des\\RS\\Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz->/arch_m1/
> smi/des/RS/Pat/10DJ/121.D5-30/1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
> 11/24/2009 08:16:42 ; 1259068602'
>
> TIA

jon at jon-desktop:~/pytest$ cat log.txt
K:\sm\SMI\des\RS\Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz->/arch_m1/
smi/des/RS/Pat/10DJ/121.D5-30\1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
11/24/2009 08:16:42 ; 1259068602

>>> log = open('/home/jon/pytest/log.txt', 'r').readlines()
>>> log
['K:\\sm\\SMI\\des\\RS\\Pat\\10DJ\\121.D5-30\\1215B-B-D5-BSHOE-MM.smz-
>/arch_m1/\n', 'smi/des/RS/Pat/10DJ/121.D5-30\\1215B-B-D5-BSHOE-
MM.smz ; t9480rc ;\n', '11/24/2009 08:16:42 ; 1259068602\n']

See -- it's not doing anything :)

Although, "Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz" and "Pat
\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz" seem to be fairly different -- are
you sure you're posting the correct output!?

Jon.



More information about the Python-list mailing list