This is a simple issue. I use jupyter notebook for python and usually deal with pdfs using pymupdf.
I usually define pdf = fitz.open('dir/to/file.pdf')
but somethimes I forget to close the file before i redefine pdf = fitz.open('dir/to/other_file.pdf')
Sometimes I need to (for example) move or delete file.pdf
(the original file) but I can't because python is using it.
Not being an expert, I don't know how to close this file when I have redefined the variable pdf
, as obviously pdf.close()
would close 'other_file.pdf' and I end up reeinitializing my .ipynb file, which feels dumb.
How can I access an object which variable name has been redefined?