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
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With