[Tutor] sprintf-like functionality in Python (fwd)
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Mon Aug 25 15:27:54 EDT 2003
Hi Vicki,
I'm forwarding this to the Tutor list. Please be more careful to send
your replies to tutor at python.org next time.
I do not want to become a bottleneck! Why settle for one brain when you
can use the whole community's? *grin*
Anyway, for the error you're getting, take a closer look at the original
example. The original code passes two arguments to the int() function.
Hope this helps!
---------- Forwarded message ----------
Date: Mon, 25 Aug 2003 12:25:14 -0500 (EST)
From: Vicki Stanfield <vicki at thepenguin.org>
To: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] sprintf-like functionality in Python
> We can find out more about String Formatting here:
>
> http://www.python.org/doc/lib/typesseq-strings.html
> http://www.python.org/doc/tut/node9.html#SECTION009100000000000000000
>
>
>> 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.
>
>
> Is this what you're looking for?
>
>
> ###
>>>> chr(int('0x32', 16))
> '2'
>>>> chr(int('0x35', 16))
> '5'
> ###
Thanks. I am closer, and this helps, but I am now getting an error. I am
trying to do:
print "converted " +chr(int(output),16)
and am getting this:
TypeError: chr() takes exactly 1 argument (2 given)
You give two arguments above. What is MY problem?
--vicki
More information about the Tutor
mailing list