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

Peter Otten __peter__ at web.de
Tue Sep 22 15:24:17 CEST 2015


richard kappler wrote:

[Richard, please don't top-post. Thank you]

> On Tue, Sep 22, 2015 at 8:58 AM, Mark Lawrence <breamoreboy at yahoo.co.uk>
> wrote:
 
>> On 22/09/2015 13:37, richard kappler wrote:
>>> I have tried:

>>> #!/usr/bin/env python
>>>
>>> with open('input/test.xml', 'r') as f1:
>>>      with open('mod1.xml', 'a') as f2:
>>>          for line in f1:
>>>              s = ('\x02' + line + '\x03')
>>>              f2.write(s)
>>>
>>> as well as the same script but using .join, to no avail. What am I
>>> missing?

>> Your line has EOL on the end.  Getting rid of the unneeded brackets try:-
>>
>> s = '\x02' + line[:-1] + '\x03\n'
 

> Thanks for the reply Mark, tried that, same result.

That is *very* unlikely.

Verify that you deleted the existing mod1.xml. As you open the file in 
append mode existing faulty lines persist.




More information about the Tutor mailing list