推荐学习书目
› 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
Weakdancer
V2EX  ›  Python

使用httplib2模块时遇到的奇怪问题

  •  
  •   Weakdancer ·
    weakdancer · Feb 13, 2011 · 6602 views
    This topic created in 5704 days ago, the information mentioned may be changed or developed.
    Traceback (most recent call last):
    File "C:\Users\WeakDancer\Desktop\mail.py", line 7, in <module>
    import httplib2
    File "C:\Users\WeakDancer\Desktop\httplib2.py", line 5, in <module>
    http = httplib2.Http()
    AttributeError: 'module' object has no attribute 'Http'
    >>>

    > http = httplib2.Http()
    这句创建一个实例,在shell中正常,文件直接执行就报错,很奇怪。
    3 replies  •  1970-01-01 08:00:00 +08:00
    mrluanma
        1
    mrluanma  
       Nov 11, 2011
    这个错误是因为你把代码保存成了 httplib2.py, python 命令行在执行的时候, 会把当前目录加入 sys.path 里, 所以 import httplib2 实际上是导入你自己写的这个 httplib2.py, 这个 module 里自然没有定义 Http 了.
    c
        2
    c  
       Nov 11, 2011
    Weakdancer
        3
    Weakdancer  
    OP
       Nov 11, 2011
    @mrluanma @c 多谢,这个问题就是名称空间的问题,我后来知道了,不过我自己都把这个问题给忘了。

    九个月以前的问题也有人回答,很感动啊。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1336 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 16:51 · PVG 00:51 · LAX 09:51 · JFK 12:51
    ♥ Do have faith in what you're doing.