【发布时间】:2014-04-30 01:32:36
【问题描述】:
摘录:
file = open("D:\\DownloadFolder\\test.mp3", "wb")
def callback(data):
file.write(data)
sizeWritten += len(data)
print(sizeWritten)
connect.retrbinary('RETR test.mp3', callback)
print("completed")
Python 显然抱怨我没有定义sizeWritten,但我不确定我应该在哪里定义它。如果我将sizeWritten = 0 放在函数之前,它仍然会给出错误local variable 'sizeWritten referenced before assignment。我该怎么做?
【问题讨论】:
-
这是 Python 2 还是 3?