[Tutor] More confusion on conversion

Reggie Dugard reggie at merfinllc.com
Thu Oct 30 15:08:36 EST 2003


Vicki,

If I understand you correctly you simply want something like:

	port.write('%02X' % length)

This should write 2 bytes on the port, one for each hex digit.  If I'm
misunderstanding what you want, maybe you can clarify it a bit more.

Also, I'm sending this back to the list so that people more
knowledgeable than me can help you out as well.

Good luck with your problem.

Reggie

On Thu, 2003-10-30 at 11:23, Stanfield, Vicki {D167~Indianapolis} wrote:
> Pardon my stupidity here, but how does one write this so that I can insert it into my code. It does just what I want, but I need to write those individual values out on the serial port. I tried:
> 
> for each in [ hex(ord(x)) for x in '%02X' % length ]:
>                     port.write(each)
>                     
> but that wrote the 30 78 30 30 for the 0x00 and 30 78 30 38 for the 0x08. What I need is to write just the hex 30 and then a hex 38. Can you give me a lesson? I tried 
> 
> for each in [ hex(ord(x)) for x in '%02X' % length ]:
>                     new=string.replace(each,'0','\')
>                     port.write(new)
>                     time.sleep(.01)
>                     print new
> 
> But I get an invalid token error on the close parenthesis in the string replace statement.
> 
> --vicki
> 
> -----Original Message-----
> From: Reggie Dugard [mailto:reggie at merfinllc.com]
> Sent: Thursday, October 30, 2003 1:35 PM
> To: Vicki Stanfield
> Cc: tutor at python.org
> Subject: Re: [Tutor] More confusion on conversion
> 
> 
> Ok I won't ask :-).  How about something like:
> 
> >>> length = 10
> >>> [ hex(ord(x)) for x in '%02X' % length ]
> ['0x30', '0x41']
> >>>
> 
> Reggie
> 






More information about the Tutor mailing list