newbie str to int
Cliff Wells
logiplexsoftware at earthlink.net
Tue Oct 2 13:30:43 EDT 2001
On Monday 01 October 2001 21:22, James wrote:
> I am switching from Perl to Python, and would
> like to convert string '123abc' to integer 123.
>
> foo = int('123abc') # error
> foo = string.atoi('123abc') #error
> foo = eval('123abc') # error
> Why doing simple thing like this is so complicated ?
I think the real question is why you have ill-defined data like '123abc'. Is
this an int followed by a string or a big hex number? I think I would attack
this problem at the source: whatever piece of code generated that data should
be modified to insert a delimiter or not concatenate two bits of unrelated
data.
--
Cliff Wells
Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308
(800) 735-0555 x308
More information about the Python-list
mailing list