Questions tagged «attributeerror»


14
AttributeError:“模块”对象没有属性
我有两个python模块: py import b def hello(): print "hello" print "a.py" print hello() print b.hi() b.py import a def hi(): print "hi" 当我跑步时a.py,我得到: AttributeError: 'module' object has no attribute 'hi' 错误是什么意思?我如何解决它?

5
AttributeError(“'str'对象没有属性'read'”)
在Python中,我得到一个错误: Exception: (<type 'exceptions.AttributeError'>, AttributeError("'str' object has no attribute 'read'",), <traceback object at 0x1543ab8>) 给定python代码: def getEntries (self, sub): url = 'http://www.reddit.com/' if (sub != ''): url += 'r/' + sub request = urllib2.Request (url + '.json', None, {'User-Agent' : 'Reddit desktop client by /user/RobinJ1995/'}) response = urllib2.urlopen (request) jsonofabitch …

8
__getattr__在模块上
如何实现等效的 __getattr__在类,模块上于a? 例 当调用模块的静态定义的属性中不存在的函数时,我希望在该模块中创建一个类的实例,并使用与该模块上的属性查找失败相同的名称调用该方法。 class A(object): def salutation(self, accusative): print "hello", accusative # note this function is intentionally on the module, and not the class above def __getattr__(mod, name): return getattr(A(), name) if __name__ == "__main__": # i hope here to have my __getattr__ function above invoked, since # salutation …

16
为什么Python 3.6.1抛出AttributeError:模块'enum'没有属性'IntFlag'?
我刚刚为MacOS X安装了Python 3.6.1 当我尝试运行控制台(或使用Python3运行任何命令)时,抛出此错误: AttributeError: module 'enum' has no attribute 'IntFlag' $ /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 Failed to import the site module Traceback (most recent call last): File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 544, in <module> main() File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 530, in main known_paths = addusersitepackages(known_paths) File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 282, in addusersitepackages user_site = getusersitepackages() File …

3
AttributeError:'模块'对象没有属性'urlretrieve'
我正在尝试编写一个程序,该程序将从网站上下载mp3,然后将它们加入在一起,但是每当我尝试下载文件时,都会出现此错误: Traceback (most recent call last): File "/home/tesla/PycharmProjects/OldSpice/Voicemail.py", line 214, in <module> main() File "/home/tesla/PycharmProjects/OldSpice/Voicemail.py", line 209, in main getMp3s() File "/home/tesla/PycharmProjects/OldSpice/Voicemail.py", line 134, in getMp3s raw_mp3.add = urllib.urlretrieve("http://www-scf.usc.edu/~chiso/oldspice/m-b1-hello.mp3") AttributeError: 'module' object has no attribute 'urlretrieve' 导致此问题的行是 raw_mp3.add = urllib.urlretrieve("http://www-scf.usc.edu/~chiso/oldspice/m-b1-hello.mp3")

3
AttributeError:模块“时间”在Python 3.8中没有属性“时钟”
我已经编写了生成公共和私有密钥的代码。它在Python 3.7上运行良好,但在Python 3.8中失败。我不知道在最新版本中它怎么会失败。为我提供一些解决方案。 这是代码: from Crypto.PublicKey import RSA def generate_keys(): modulus_length = 1024 key = RSA.generate(modulus_length) pub_key = key.publickey() private_key = key.exportKey() public_key = pub_key.exportKey() return private_key, public_key a = generate_keys() print(a) Python 3.8版本中的错误: Traceback (most recent call last): File "temp.py", line 18, in <module> a = generate_keys() File "temp.py", …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.