2024-10-01 13:42:40 发布
网友
我需要能够关闭PDF,但是我还没有弄清楚如何在PyPDF2中使用python2.7
我在下面打开它,然后尝试.close():
input1 = PdfFileReader(open(var_loopingpath+f,"rb"))
然后得到错误:
'PdfFileReader' object has no attribute 'close'
谢谢。在
使用with并且不必费心关闭文件:
with
with open(var_loopingpath+f,"rb") as pdf_file: input1 = PdfFileReader(pdf_file) # rest of code
这样,当超出范围时,Python将关闭pdf_file。在
pdf_file
使用
with
并且不必费心关闭文件:这样,当超出范围时,Python将关闭
pdf_file
。在相关问题 更多 >
编程相关推荐