Possible Duplicate:
How to close pyPDF “PdfFileReader” Class file handle
I'm running Python 2.7 on Win 64bit. I'm trying to download a pdf to file, open the pdf, extract the text, and then at the end delete the pdf, but getting an error when I try to delete the python (using the python code and manually trying to delete the pdf - windows says the file is in use by pythonw). My simplified code:
from PyPDF2 import PdfFileReader
pdf_url = "www.Url for.pdf"
file_path = 'myfile.pdf'
f = file(file_path, 'wb')
f.write(urllib2.urlopen(pdf_url).read())
f.close()
pdf = PdfFileReader(open(file_path, 'rb'))
os.remove(file_path)
Error returned:
WindowsError: [Error 32] The process cannot access the file because it is
being used by another process: 'myfile.pdf'
Any suggestions?