[Tutor] stx, etx (\x02, \x03)
Mark Lawrence
breamoreboy at yahoo.co.uk
Tue Sep 22 16:23:06 CEST 2015
On 22/09/2015 15:07, richard kappler wrote:
>>
>>> That is *very* unlikely.
>>
>
> Perhaps, but I assure you it is what is happening.
>
>>
>>> Verify that you deleted the existing mod1.xml. As you open the file in
>>> append mode existing faulty lines persist.
>>
>
> I did, hence the above assurance.
>
> Here's the modified code:
>
> #!/usr/bin/env python
>
> stx = '\x02'
> etx = '\x03'
>
> with open('input/PS06Test_100Packages.xml', 'r') as f1:
> with open('mod1.xml', 'a') as f2:
> for line in f1:
> s = stx + line[:-1] + etx
> f2.write(s)
>
> mod1.xml has the \x02 hex at the beginning of line 1, then line 2 and all
> further lines begin with the \x03 hex then the \x02 hex and then the line.
>
> regards, Richard
Reread my original post and you'll see that your "s" isn't set the same
way mine was.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Tutor
mailing list