laslavinco laslavinco - 7 months ago 67
Python Question

Python error TypeError: must be string or buffer, not instance

i am trying to download some images which are listed in QListWidget i am passing the links to the urllib but its giving me TypeError: must be string or buffer, not instance this error. I tried looking up here but couldn't find any solution here is my code. Thanks

def downloadStuff(self):
files = self.listWidget.selectedItems()
for filename in files:
filename = filename.text()
filename = str(filename)
print filename
xfilename = filename.split('/')[-1]
with open('D:/'+xfilename,'wb') as imageFile:
print filename


It's hard to say for sure without seeing the stack trace, but I suspect this line:


Should instead be:


Incidentally, you don't need the imageFile.close() line, because the with statement closes the file for you automatically.