Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python AttributeError: 'module' object has no attribute 'atoi'

Tags:

python-3.x

I tried to run following program of using python 3.2 , there is error: 'module' object has no attribute 'atoi' Can anybody tell me what should I do to fix this? i really appreciate it !

import string
def converttoint(str):
    try:
        value = string.atoi(str)
        return value
    except ValueError:
        return None
like image 668
user3034622 Avatar asked Nov 26 '13 04:11

user3034622


1 Answers

string.atoi has been deprecated for a very long time. Since Python 2.0, in fact, and it doesn't exist in Python 3.

Simply use

value = int(s)

instead, and don't call your variable str. That's a bad habit, as it shadows the builtin string type str.

like image 97
DSM Avatar answered Oct 14 '22 17:10

DSM