[Tutor] stx, etx (\x02, \x03)
Oscar Benjamin
oscar.j.benjamin at gmail.com
Tue Sep 22 18:32:29 CEST 2015
On 22 September 2015 at 15:44, richard kappler <richkappler at 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
More information about the Tutor
mailing list