Soni L. writes:

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

The only parallel I see is that you read a file found on a path.
Modules are *special* because they're the only built-in object that
normally lives in a file "somewhere" (except for the interpreter
itself, which is pretty meta).  All the other Python objects live in
modules.  That's why modules have a keyword for accessing them and
binding names (three keywords, in fact!)  Because a Python program is
composed from a versioned language and an environment and an
application and libraries, finding the right module can be complex.
Once found, "import" goes and does module-specific things, some of
which are also moderately complex.  All this complexity is enough to
justify three keywords!

Other resources are mostly specific to applications.  They don't need
the complexity of path search all that often (though not all that
rarely either).  When they do, it's not obvious that the right way to
search is going to be the same as searching for a module (certainly
you'll use a different path and the test for whether a file appears to
contain a valid resource will be resource-specific).  Once you
identify a file containing a resource, what you do with it will be
completely different from the normal import process (unless it's
Python code you're intending to import, in which case why not just use
an import statement?)

Finally, import is a statement because it changes the environment of
the program globally.  The imported defs and globals become part of
the program, and those objects are linked to the program by the
top-level code.  What other resources do that?  It's a matter of style
to do that in a statement which can't be included in an expression,
but I think that it's a good thing that Python does it that way.

I see some parallels, but I'm definitely in the camp of "confusingly
similar" rather than "instructively similar", and I definitely don't
see a need for a syntax change to enable importing anything inside
expressions.

 > The python tutorial doesn't even touch on managing and importing 
 > resources.

Why would it?  Resource management is an application-level concept
which is far more general than Python, and far more diverse than the
standard suite of Python objects.  It is not a language-level concept.
The language manages code and data objects, and the tutorial explains
the basics of the language-level facilities for working with them *in
Python*.  To the extent that objects may be contained in external
files, those files are read with open() and the methods on the
resulting file object.  The tutorial explains those, and even goes on
to describe object interchange with JSON, and mention Python-specific
data persistence via pickle.  That's as far as it should go, IMO.

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

Reply via email to