def unpack_defaults():
open("templates/index.html", "w").write(f"{from ganarchy.templates
import 'index.html'}")
This is non-idiomatic to not only Python, but any language I've seen
thus far in my career.
What does this achieve which reading the file and then writing the
file does not?
uses the import machinery.
On Sun, Jan 19, 2020 at 11:11 PM Soni L. <fakedme+py@gmail.com
<mailto:fakedme%2Bpy@gmail.com>> wrote:
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
<mailto:python-ideas@python.org>
To unsubscribe send an email to python-ideas-leave@python.org
<mailto:python-ideas-leave@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/4QUAJT...
Code of Conduct: http://python.org/psf/codeofconduct/