kelesi / mtga-utils

Magic the Gathering: Arena related stuff (Card collection export)
MIT License
53 stars 13 forks source link

changes to allow mtga_log.py to be imported as a module #24

Closed bhughes339 closed 4 years ago

bhughes339 commented 4 years ago

mtga_log.py is very useful for my MTG Arena projects, but when you try to import it as a module (from mtga_utils import mtga_log with mtga_utils in a subfolder) it throws an error:

Traceback (most recent call last):
  File "c:/Users/billy/code/mtga_decklist_viewer/mtga_decklist_viewer.pyw", line 11, in <module>
    from mtga_utils import mtga_log
  File "c:\Users\billy\code\mtga_decklist_viewer\mtga_utils\mtga_log.py", line 6, in <module>
    import scryfall
ModuleNotFoundError: No module named 'scryfall'

This is due to how Python handles relative imports—it's looking for the scryfall module in the base folder instead of the mtga_utils folder.

This solution should work fine. Unfortunately, the repo name mtga-utils is not a valid package name, so I couldn't simply change the import code to from mtga-utils import scryfall.

kelesi commented 4 years ago

You could just rename the directory where you have mtga-utils to mtga_utils and it should work.

kelesi commented 4 years ago

Is the suggested aproach ok with you? If not please create an issue.