V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
endoffight
V2EX  ›  Python

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

  •  
  •   endoffight ·
    phpgao · 2014-07-29 10:52:06 +08:00 · 4290 次点击
    这是一个创建于 3576 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我在交互模式下可以导入并运行,没有问题!

    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'

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

    $ python test.py
    utf-8
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5702 人在线   最高记录 6547   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 06:54 · PVG 14:54 · LAX 23:54 · JFK 02:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.