On Mon, Jan 20, 2020 at 4:15 PM Soni L. <[email protected]> wrote:

>
> I generally do that but I was frustrated and exhausted. That is, that
> may have been slightly passive-aggressive... Sorry.
>

and yet you barely trimmed this one ;-)

in any case the whole thing I'm arguing for in this thread, is to *draw
> parallels* between module imports and resource imports.


The problem I see with all this is that there isn't much of a parallel --
modules can only contain Python objects, and, like the title of this thread
indicates, the only two python objects that directly map to a file are
strings and bytes.

You *may* be able to do something directly with strings, but most likely
you'll pass it off to something else: a template renderer, JSON parser,
what have you. And I can’t think of a single instance where you would just
want the bytes in a file without processing them into a Python object.
Given that you have to do that next step anyway, I don't see much gain here.

That is: what’s wrong with hard-coding, say, a template into Python source
and assigning it a string?

And we DO have importlib and setuptools solutions already -- if you really
think they're useful, then better documentation is in order.

That being said, I have wanted to put resources in with my Python code, for
two reasons:

1) It’s easier to bundle them up with the package (I used to use py2exe and
the like a lot)

2) it’s nice to be able to simply import something and have the Python
object I want right away.

For (1): this is made easier by the current packaging solutions — it could
be a bit cleaner (messing around with __file__ is pretty ugly) — so by all
means explore the available solutions and maybe make a better one.

For (2) — see above— I want the relevant Python object, not just the string
or bytes. A good example of this is the utilities (img2py I think) that
come with wxPython: They bundle up a set of images into a Python module
that creates wxImages on the fly. So you can import the module, and have a
set of wxImages ready to go. That is pretty nice.

I do think there could be some utilities to make that kind of thing easier,
but making it easy, with a built in, to simply get the bytes or text from a
file wouldn’t buy us much.

-CHB

-- 
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
-- 
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/4XE7C52QULKHTLOOLHU3B76ETOIIWGDD/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to