I know this question has been asked before quiet a lot on SO and elsewhere too. I still couldn\'t get it done. And im sorry if my English is bad
Removing file in lin
Pythonic way of reading from or writing to a file is by using a with
context.
To read a file:
with open("/path/to/file") as f:
contents = f.read()
#Inside the block, the file is still open
# Outside `with` here, f.close() is automatically called.
To write:
with open("/path/to/file", "w") as f:
print>>f, "Goodbye world"
# Outside `with` here, f.close() is automatically called.
Now, if there's no other process reading or writing to the file, and assuming you have all the permission you should be able to close the file. There is a very good chance that there's a resource leak (file handle not being closed), because of which Windows will not allow you to delete a file. Solution is to use with
.
Further, to clarify on few other points:
close(..)
that takes an integer file descriptor. Not string as you passed.