Python style questions
Cary O'Brien
cobrien at Radix.Net
Fri Mar 16 12:03:48 EST 2001
In article <98tclh$ap6$2 at lahti.tasking.nl>,
Dick Streefland <dick_streefland at tasking.com> wrote:
>cobrien at Radix.Net (Cary O'Brien) wrote:
>| 4. I need to change things like "88aa99bb" (hex string) into integers. Should I
>|
>| a. use expr("0x"+s)
>| b. not use such things
>| c. ???
>
>c. use string.atoi(s, 16), or for Python >= 2.0, the builtin int(s, 16).
>
Hmm...
>>> int('abcd',16)
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: int requires exactly 1 argument; 2 given
>>>
Is this a 2.0 feature?
>>> import string
>>> string.atoi('abcd',16)
43981
>>>
Ok, that works. Missing in my "Python essential reference" though.
Thanks...
-- cary
More information about the Python-list
mailing list