Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

added sorting option by using list #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Masterjx9
Copy link

whenever I used references = pdf.get_references_as_dict(sort=True) it would fail saying:

  File "C:\Users\user\Scripts\PDFx\test.py", line 9, in <module>
    references = pdf.get_references_as_dict(sort=True)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\users\user\scripts\pdfx\pdfx\pdfx\__init__.py", line 168, in get_references_as_dict
    return self.reader.get_references_as_dict(reftype=reftype, sort=sort)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\users\user\scripts\pdfx\pdfx\pdfx\backends.py", line 177, in get_references_as_dict
    for r in sorted(refs) if sort else refs:

This makes sense because you can't sort a set. However you can ensure that the data is sorted by using a list from the beginning. Thus I am a parameter in the PDFx called that allows you to select if you want to use a set or a list. The backends.py has been updated to handle if its a set or list.
Also the sort param from the get_references_as_dict and get_references function has been removed.

It can be used like this pdf = pdfx.PDFx("test.pdf", references_data_structure="list") or like this pdf = pdfx.PDFx("test.pdf", references_data_structure="list")

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant