int() built-in and hex "0x..." strings

Cliff Crawford cjc26 at nospam.cornell.edu
Wed Aug 1 03:43:41 CEST 2001


* Bruce Edge <bedge at troikanetworks.com> menulis:
| 
| Do I really need to parse out the '0x' 1st, then based on it's
| absence/presence do either:
| int('80', 16)
| or
| int('80')
| ?
| 
| Is there another int() type lib func that I should use instead?

You can do int('0x80', 0) -- passing 0 as the second argument causes
int() to try to guess the base from the format of the string.


-- 
Cliff Crawford            http://www.sowrong.org/
A sign should be posted over every campus toilet:
"This flush comes to you by courtesy of capitalism." 
                                 -- Camille Paglia



More information about the Python-list mailing list