newbie str to int

Chris Barker chrishbarker at home.net
Tue Oct 2 13:16:47 EDT 2001


James wrote:

> Perl
> $foo = '123abc' + 0;

Another reason why this is a very BAD idea:

>>> int("1230")
1230

just what you want.

>>> int("123O")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: invalid literal for int(): 123O

what when wrong here? well, depending on what font you are using, timay
be obvious: that last character is the letter, "oh" not the number,
zero. I am very glad that Python chatches this kin do f very non obvious
typo fpr me: what did the person typing that string in mean???


-Chris


-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list