We have importlib. We have importlib.resources. We can import modules.
We cannot (yet) import resources using the same-ish module import machinery.
It would be nice if we could.
I'm thinking of something like:
from foo.bar import resources "foo.txt" as foo, "bar.txt" as bar #
string imports
from foo.bar import bresources "foo.txt" as bfoo, "bar.txt" as bbar #
bytes imports
or maybe:
foo = f"{from foo.bar import 'foo.txt'}" # string imports
bbar = fb"{from foo.bar import 'bar.txt'}" # bytes imports
altho I have a bit of a preference for the latter.
I feel like these would be nice, and useful for packaging default
configs, templates, and whatnot:
def unpack_defaults():
open("templates/index.html", "w").write(f"{from ganarchy.templates
import 'index.html'}")
open("templates/project.html", "w").write(f"{from ganarchy.templates
import 'project.html'}")
open("templates/config.toml", "w").write(f"{from ganarchy.templates
import 'config.toml'}")
You'd just do this, effortlessly, no need to mess with importlib, it
would just work and it'd be easy to teach ppl and get them to use it.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/4QUAJTKOXD27GHPNMN4N3CQRU3LHISY2/
Code of Conduct: http://python.org/psf/codeofconduct/