I recently updated PyMuPDF/fitz and so updated my code that uses it to update my use of fitz methods to match the updated naming convention (see PyMuPDF > Deprecated Names).
Problem: when I call a function I wrote to use fitz's Page.get_text() it sometimes exists as an attribute under the deprecated name and sometimes is in the updated name. Either way it is called, it is imported in the same script, but in one version second script imports the script that imports fitz (via from fitz import fitz
).
How can I gain visibility into where these different sets are attributes are introduced?
Steps taken so far to disentangle and debug: I confirmed the version of PyMuPDF is the same in both situations via this StackOverflow answer with:
print(pkg_resources.get_distribution('PyMuPDF').version)
=> 1.21.0
I checked the attributes of the object with:
print(dir(page))
It is a consistent pattern based on which script I use to call my function. #1 w/ getText (deprecated): screenshot showing version number 1.21.0 and getText as an attribute
#2 w/ get_text: screenshot showing version number 1.21.0 and get_text as an attribute
Current solution:
for page in doc:
try:
text += page.get_text()
except AttributeError:
text += page.getText()