Python Forum
pyPDF2 PDFMerger close pensding file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pyPDF2 PDFMerger close pensding file
#2
pdfmerger is not leaving the file open, you are. Here you open a file and never close it.
merger.append(PdfFileReader(open(os.path.join(dirName, fname),'rb')))
I would use a context manager to automatically close the file.
with open(os.path.join(dirName, fname),'rb') as file:
    merger.append(PdfFileReader(file))
Reply


Messages In This Thread
pyPDF2 PDFMerger close pensding file - by japo85 - Jul-27-2022, 01:42 PM
RE: pyPDF2 PDFMerger close pensding file - by deanhystad - Jul-27-2022, 03:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PyPDF2 deprecation problem gowb0w 5 4,736 Sep-21-2023, 12:38 PM
Last Post: Pedroski55
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 1,702 Aug-07-2023, 05:32 AM
Last Post: DPaul
  Save and Close Excel File avd88 0 3,297 Feb-20-2023, 07:19 PM
Last Post: avd88
  Pypdf2 will not find text standenman 2 997 Feb-03-2023, 10:52 PM
Last Post: standenman
  PyPDF2 processing problem Pavel_47 6 9,926 May-04-2021, 06:58 AM
Last Post: chaitanya
  How to close file handler or log file on each iteration Mekala 3 5,227 Aug-16-2020, 03:15 PM
Last Post: snippsat
  How To Find an Opening and Closing String, Copying Open/Close/Contents to New File davidshq 1 2,080 Mar-03-2020, 04:47 AM
Last Post: davidshq
  How can I Open and close .py file from python scripts SayHiii 9 5,900 Dec-17-2019, 06:10 AM
Last Post: Malt
  Problem with installing PyPDF2 Pavel_47 2 6,125 Nov-10-2019, 02:58 PM
Last Post: Pavel_47
  Does python guarantees that file.write() works without file.close() ? kryptomatrix 7 4,092 Oct-21-2019, 11:28 AM
Last Post: kryptomatrix

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020