[Tutor] Another parsing question

Stanfield, Vicki {D167~Indianapolis} vicki.stanfield at ROCHE.COM
Mon Mar 15 15:29:57 EST 2004


I have inherited a project which writes some data to a file in
hexadecimal format as 0x11, 0x4, etc. The hex values are pipe-delimited
as so: 0x11|0x4|0x14 

I need to parse the file to transmit the values over a serial port as
hex, but when I send the data that I have parsed out, I get it sending
the 0, the x, the 1, and another 1 instead of the hex value for 0x11.
How would one grab the whole thing as hex? Here is what I am doing now:

	for line in data_file.readlines():
                    if len(line)>1:
                        tokens=line.split("|")
                        i=0
                        for piece in tokens:
                            port.write(piece)
                            time.sleep(S_INTERVAL)
                            i = i + 1

It seems to me that I have done this before, but I have searched my code
base and not found an example.

TIA,
--vicki

"A pessimist sees the difficulty in every opportunity; an optimist sees
the opportunity in every difficulty." 
-- Winston Churchill 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040315/22c36e06/attachment-0001.html


More information about the Tutor mailing list