[Tutor] sprintf-like functionality in Python

Neil Schemenauer nas-pytut at python.ca
Mon Aug 25 12:55:05 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



More information about the Tutor mailing list