[Tutor] stx, etx (\x02, \x03)

richard kappler richkappler at gmail.com
Tue Sep 22 16:44:24 CEST 2015


>
>>
> Reread my original post and you'll see that your "s" isn't set the same
> way mine was


No.  My implementation of your code:

#!/usr/bin/env python

with open('input/PS06Test_100Packages.xml', 'r') as f1:
    with open('mod1.xml', 'a') as f2:
        for line in f1:
            s = '\x02' + line[:-1] + '\x03\n'
            f2.write(s)

gives me:
line 1 starts with the \x02 hex then the line
line 2 is the \xo3 hex alone
line 3 starts with the \x02 hex then the line
line 4 is the \x03 hex alone
lather rinse repeat.

So I mispoke, please accept my apology, it wasn't exactly the same result
as my original code, it put the \x03 on it's own line.

Oddly enough, I'm wondering if it's the xml that's making things screwy. I
ran a little experiment, creating a test text file:

line one
line two
line three
line four

and ran the above code (changing the file names of course) and it came out
perfect. Each line begins with the \x02 hex and ends with the \x03 hex.

regards, Richard


More information about the Tutor mailing list