AttributeError:...对象没有属性'update'

时间:2017-02-24 16:24:49

标签: python methods

我有以下代码从URL列表中下载HTML内容。每当我运行它时,我会收到一条错误消息“Traceback(最近一次呼叫最后一次):

tan()

这是代码:

test:
    [junit] Running CalculatorTest
    [junit] Testsuite: CalculatorTest
    [junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 se
c
    [junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 se
c
    [junit]
    [junit] Null Test:  Caused an ERROR
    [junit] CalculatorTest (wrong name: package/CalculatorTest)
    [junit] java.lang.NoClassDefFoundError: CalculatorTest (wrong name: package/C
alculatorTest)

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您正在尝试在函数上调用方法而不是对象。而是致电:

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)