pmaupin / pdfrw

pdfrw is a pure Python library that reads and writes PDFs
Other
1.86k stars 271 forks source link

Fixing decodegraphics.py import error #215

Open Lucas-C opened 3 years ago

Lucas-C commented 3 years ago

Given this code:

import os, pdfrw, sys
sys.path.append(os.path.join(os.path.dirname(pdfrw.__file__), '../examples'))
from rl2.decodegraphics import parsepage

This fix avoids the following error with Python 3.7:

Traceback (most recent call last):
  File "./extract_table.py", line 3, in <module>
    from rl2.decodegraphics import parsepage
  File "/opt/pdfrw/pdfrw/../examples/rl2/decodegraphics.py", line 377, in <module>
    class _ParseClass(object):
  File "/opt/pdfrw/pdfrw/../examples/rl2/decodegraphics.py", line 378, in _ParseClass
    dispatch = findparsefuncs()
  File "/opt/pdfrw/pdfrw/../examples/rl2/decodegraphics.py", line 362, in findparsefuncs
    for key, func in globals().items():
RuntimeError: dictionary changed size during iteration
Lucas-C commented 3 years ago

This PR has been merged in @sarnold fork: https://github.com/sarnold/pdfrw