eval('000052') = 42?

Erik Max Francis max at alcyone.com
Wed Feb 21 00:17:51 EST 2007


Astan Chee wrote:

> I just tried to do
> eval('00052') and it returned 42.
> Is this a known bug in the eval function? Or have I missed the way eval 
> function works?

String literals beginning with a 0 are in octal.

Besides, using eval for such a narrow case is extremely unwise.  Instead 
use int:

 >>> int('00052')
52

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
   God grant me to contend with those that understand me.
    -- Thomas Fuller



More information about the Python-list mailing list