Excerpt:
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 obviously complains that I didn't define sizeWritten
, but I'm not sure where I should define it. If I put sizeWritten = 0
before the function it still gives an error local variable 'sizeWritten referenced before assignment
. How should I do this?