[Tutor] sprintf-like functionality in Python

Vicki Stanfield vicki at thepenguin.org
Mon Aug 25 11:00:12 EDT 2003


I am looking for something like sprintf functionality in Python. I have
seen several things on google groups that seem to indicate that sprintf
itself exists in Python but I haven't really found an explanation of it.
What I am trying to do is take data with comes into my program as hex and
convert it to ASCII. For instance, I get:

0x30
0x35

This represents the length of 5 (05), and I need to convert it to the
integer 5. The problem is that the first digit might be significant as in
(0x32 0x35) which translates to 25. I am not sure how to put the two
together in Python. In C, I'd use sprintf. In short, I start with 0x32
0x35 and need to translate it to the integer 25. Thanks.

--vicki



More information about the Tutor mailing list