I’m building a simple function that works (delete the files). But In the end I want to return the list of the files that were effectively deleted.
This is the function:
def deleteFiles(files):
# empty list
RemovedFiles = list()
for file in files:
# Delete the file
if os.remove(file):
RemovedFiles.append(file)
return RemovedFiles
I run this function with:
print deleteFiles([/home/xyz/xyz.zip])
This effectively deletes the xyz.zip but returns an empty list: []. What am I doing wrong here?
The problem is that
os.removedoes not return anything.You can however
tryandexcept: