V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · 4750 views
    This topic created in 4292 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   ·   1454 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 16:54 · PVG 00:54 · LAX 09:54 · JFK 12:54
    ♥ Do have faith in what you're doing.