![](/img/trans.png)
[英]AttributeError: 'Price' object has no attribute 'update'
[英]AttributeError: … object has no attribute 'update'
我有以下代码从URL列表下载HTML内容。 每当我运行它时,我都会收到一条错误消息,指出“追踪(最近一次通话过去):
File "*******", line 16, in <module>
**hashMessage = computeMD5(url)**
File "*******", line 13, in computeMD5
**m.update(message)**
*AttributeError: 'builtin_function_or_method' object has no attribute 'update'*
这是代码:
import hashlib
from hashlib import md5
import os
fh = open("****.txt", 'r')
for line in fh:
url = line
url = url.replace('\n', '')
def computeMD5(message):
m = hashlib.md5
m.update(message)
return m.hexdigest()
hashMessage = computeMD5(url)
print hashMessage
os.system(" wget -O /desktop/Html" + hashMessage + ".txt " + url)
我怎样才能解决这个问题?
您试图在函数而不是对象上调用方法。 而是调用:
import hashlib
from hashlib import md5
import os
fh = open("****.txt", 'r')
for line in fh:
url = line
url = url.replace('\n', '')
def computeMD5(message):
m = hashlib.md5() # instead of m = hashlib.md5
m.update(message)
return m.hexdigest()
hashMessage = computeMD5(url)
print hashMessage
os.system(" wget -O /desktop/Html" + hashMessage + ".txt " + url)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.