PDFFileReader在使用后没有关闭pdf

时间:2012-10-26 06:01:59

标签: python pdf pypdf win64

  

可能重复:
  How to close pyPDF “PdfFileReader” Class file handle

我在Win 64bit上运行Python 2.7。 我正在尝试下载pdf到文件,打开pdf,提取文本,然后在最后删除pdf,但在我尝试删除python时出错(使用python代码并手动尝试删除pdf - windows表示pythonw正在使用该文件。我的简化代码:

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)

返回错误:

WindowsError: [Error 32] The process cannot access the file because it is 
being used by another process: 'myfile.pdf'

有什么建议吗?

0 个答案:

没有答案