我尝试运行以下使用 python 3.2 的程序,出现错误:
“模块”对象没有属性“atoi”
谁能告诉我该怎么做才能解决这个问题?
对此,我真的非常感激 !
import string
def converttoint(str):
try:
value = string.atoi(str)
return value
except ValueError:
return None
最佳答案
string.atoi
已被弃用很长时间。从 Python 2.0 ,事实上,它在 Python 3 中并不存在。
只需使用
value = int(s)
相反,不要调用你的变量
str
.这是一个坏习惯,因为它会影响内置字符串类型 str
.
关于python-3.x - Python 属性错误 : 'module' object has no attribute 'atoi' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20208570/