python 3.2中用string.atoi()产生错误,如何解决?

低头思蚊香 2011-12-10 09:57:33
> > > import string
> > > string.atoi( '10 ') + 4
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
string.atoi('10') + 4
AttributeError: 'module' object has no attribute 'atoi'


我按照 [征服PYTHON:语言基础与典型应用].孙广磊.完美书签.清晰PDF版
里原样写的代码,为什么是错误的。原书用的是Python 2.5
...全文
2930 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
iambic 2011-12-10
  • 打赏
  • 举报
回复
因为没人用,所以后来标准库删了。
低头思蚊香 2011-12-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 iambic 的回复:]
好垃圾的书。

Python code

int('10') + 4
[/Quote]
能解释下为什么用string.atoi('10')不行吗?
iambic 2011-12-10
  • 打赏
  • 举报
回复
好垃圾的书。
int('10') + 4
yorath 2011-12-10
  • 打赏
  • 举报
回复
python3没有向下兼容,你要使用python3的话需要看python3的书
libralibra 2011-12-10
  • 打赏
  • 举报
回复
这啥书啊
atoi一看就是c/c++转过来的
python讲的是简洁,直接int(str)和str(int)互相转来转去多方便

37,742

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧