[英]How do you close this in Python?
我需要能夠關閉PDF,但是我無法弄清楚如何使用Python 2.7在PyPDF2中
我在下面打開它,然后嘗試.close():
input1 = PdfFileReader(open(var_loopingpath+f,"rb"))
並得到錯誤:
'PdfFileReader' object has no attribute 'close'
謝謝。
使用with
和不關閉文件的麻煩:
with open(var_loopingpath+f,"rb") as pdf_file:
input1 = PdfFileReader(pdf_file)
# rest of code
這樣,Python超出范圍時將關閉pdf_file
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.