On 22 September 2015 at 15:44, richard kappler <richkapp...@gmail.com> wrote: >> >>> >> 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
The 4th part is both the \x03 character and the \n newline character as a single string. Your version doesn't have a newline character at the end of s: #!/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) -- Oscar _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor