推荐学习书目
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 · Jul 29, 2014 · 4789 views
    This topic created in 4310 days ago, the information mentioned may be changed or developed.
    我在交互模式下可以导入并运行,没有问题!

    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 replies    2014-07-29 11:36:45 +08:00
    mengzhuo
        1
    mengzhuo  
       Jul 29, 2014
    你是不是打错模块名了……

    $ python test.py
    utf-8
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3011 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 00:21 · PVG 08:21 · LAX 17:21 · JFK 20:21
    ♥ Do have faith in what you're doing.