• 欢迎访问金笔头博客,这是一个菜鸟(伪)程序员的自留地,欢迎访问我的github:点击进入

解决AttributeError: ‘module’ object has no attribute ‘XXX’办法

python eason 5283次浏览 4个评论 扫描二维码

今天在做socket练习的时候,将写好的脚本命名为socket.py

解决AttributeError: 'module' object has no attribute 'XXX'办法

import socket

print ‘Creating socket…’

s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

print ‘Done!’

print ‘Connecting to remote host…’

s.connect((‘jinbitou.net’,80))

print s.getsockname()

print s.getpeername()

print ‘Done!’

运行的时候报错:

AttributeError: ‘module’ object has no attribute ‘socket’

解决办法:在python中import模块时,文件名不要和模块名重名,将socket.py改为其他名字即可。

 


金笔头博客, 版权所有丨如未注明 , 均为原创, 转载请注明解决AttributeError: ‘module’ object has no attribute ‘XXX’办法
喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(4)个小伙伴在吐槽
  1. Really informative blog article.Much thanks again.
    ottoman coffee table2016-02-10 16:31 Reply Windows 7 | Firefox 3.5.3
  2. This is one awesome blog post.Much thanks again. Really Great.
    30 passenger party bus2016-02-07 21:37 Reply 未知操作系统 | 未知浏览器
  3. I like what you guys are up too. Such clever work and reporting! Carry on the superb works guys I've incorporated you guys to my blogroll. I think it'll improve the value of my website :).
    eebest82016-02-04 02:06 Reply 未知操作系统 | 未知浏览器
  4. here are some hyperlinks to web-sites that we link to mainly because we think they're worth visiting
    eebest8 seo2016-01-02 16:36 Reply Windows XP | Firefox 3.0.14