On 2020-01-19 8:49 p.m., Tener Hades wrote:
> 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...@gmail.com <mailto:fakedme%2...@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-le...@python.org
    <mailto: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/


_______________________________________________
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/5WHNLGP3EZ57OJZVNTNYKVC2VDR25JPV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to