[Tutor] sprintf-like functionality in Python
Vicki Stanfield
vicki at thepenguin.org
Mon Aug 25 15:05:09 EDT 2003
> Vicki Stanfield wrote:
>> Okay I got it to work (not so elegently) using this:
>>
>> output=port.read()
>> length = chr(ord(output))
>> output=port.read()
>> newlength=length+chr(ord(output))
>> num=int(newlength)
>> print num
>
> chr(ord(x)) does is an identity function (i.e. is does nothing). I
> don't completely understand what you want but how about:
>
> length = port.read(2)
> num = int(length, 16)
>
> Does that do what you want?
>
> Neil
>
Yes, that is exactly what I needed. The problem I was running into was
that I was trying to pull it in one at a time and then put the two digits
together and translate them into a single number. Your solution is far
more useful! This is an example of me making things more complicated than
necessary. Thanks.
--vicki
More information about the Tutor
mailing list