python 安装 chardet 模块后出现了一个诡异的问题

2014-07-29 10:52:06 +08:00
 endoffight
我在交互模式下可以导入并运行,没有问题!

import chardet
chardet.detect()
function at xxxxxxxx

但是写在程序里


import chardet
import urllib
#先获取网页内容
html_doc= urllib.urlopen('http://www.baidu.com').read()
#用chardet进行内容分析
char_info = chardet.detect(html_doc)

print char_info['encoding'] # baidu



就会报错

char_info = chardet.detect(html_doc)
AttributeError: 'module' object has no attribute 'detect'

请问这是为啥?
4300 次点击
所在节点    Python
1 条回复
mengzhuo
2014-07-29 11:36:45 +08:00
你是不是打错模块名了……

$ python test.py
utf-8

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/125019

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX