Reputation: 25
I need to be able to close the PDF but I haven't been able to figure out how in PyPDF2 using Python 2.7
I open it below but then I try the .close():
input1 = PdfFileReader(open(var_loopingpath+f,"rb"))
And get the error:
'PdfFileReader' object has no attribute 'close'
Thanks.
Upvotes: 0
Views: 1656
Reputation: 81664
Use with
and don't bother with closing the file:
with open(var_loopingpath+f,"rb") as pdf_file:
input1 = PdfFileReader(pdf_file)
# rest of code
This way Python will close pdf_file
when it goes out of scope.
Upvotes: 3