1

I'm trying to build a python script which then I add to a zip file using python -m zipapp.

Everything works fine until it tries to read in my json config file, because it can't find it using directory string like "config.json" (config.json is at the root of the folder where all my code is in). So I found something that looks like it will help, which is importlib.resources.open_text("Package Name", "config.json"). The problem is that since all my python code is at the root of the folder I've created, I don't know what "Package Name" should be. Is there a default package name? And also, do I need to create __init__.py for this to work? My program works fine without __init__.py when I just run it from command-line like python __main__.py #(my entry point is in __main__.py)

Edit: I tried using "__package__" but that variable is empty.

sinoroc
  • 18,409
  • 2
  • 39
  • 70
u84six
  • 4,604
  • 6
  • 38
  • 65
  • To make things easier, non-Python files should be part of an importable Python package. Such data is then called "package data" (which is the key words you should look up for help on your question). -- If files are at the root, then I am really not sure it is possible, I would not know how. – sinoroc Jan 10 '23 at 14:49

0 Answers0