Replies: 1 comment 2 replies
-
The problem is that you instead of opening a file handle, just pass the path directly to PyPDF2: # Old and error-prone: Opening a file handle directly:
file_handle = open(filename, "rb")
reader = PyPDF2.PdfReader(file_handle)
# New: Let PyPDF2 manage file handles:
reader = PyPDF2.PdfReader(filename) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys - newbie coder here, sorry for the dumb questions. I was running PyPDF2 to merge a bunch of PDFs
Which is code I got from elsewhere on the internet. Good news - it worked, and is extremely fast!
Bad news - I then tried to move all the pdf files to a different directory, and my pc told me I couldn't, since they were being used by python. This was very annoying, and difficult to resolve.
Bad news - Now when I run the same code, I get the following error:
I don't understand why the code doesn't work when it did half an hour ago, nor why my computer thinks python is still using the pdfs, well after they've been merged (which happens almost instantaneously).
Thanks much for your help and apologies if these are stupid questions and/or badly formatted. I'm always looking to learn.
Beta Was this translation helpful? Give feedback.
All reactions