Having a __stdlib__ namespace?

Daniel Yoo dyoo at hkn.eecs.berkeley.edu
Fri Jan 10 03:02:52 EST 2003



:>Would it be a good idea to have a '__stdlib__' module that magically
:>maps its attributes to only Standard Library modules?  It would act as
:>a namespace to guarantee access to the standard library, no matter how
:>weird the sys.path might get.


Bengt Richter <bokr at oz.net> wrote:

: I just did an experiment that I don't know all the ramifications of, so don't
: take this is anything but an expriment, but if you put a file called
: __init__.py with nothing in it (mine has two bytes: '\r\n') in the Lib
: directory, so the path to it looks something like 

:    D:\Python22\Lib\__init__.py
:
: (your installation location may vary)

Hi Bengt,

I didn't think about that one... cool!  You're right though: the one
problem I'd see about is that this would be platform specific, as
Python's libraries live in "lib/pythonX.X" on some Unix systems.

I still prefer to use a magic looking name, even if there were no real
magic involved, just so that it's easier to see that something unusual
is being done.  It also makes it that much harder for a user to go
ahead and mess this beautiful scheme up by using a package generically
named Lib... *grin*.

Andrew Bennetts suggested in email about using "std" as an easy name
to type.  I'd like to subvert his suggestion and propose "__std__".


A system like this would be useful because the names of modules in the
Standard Library are generic.  This is a Good Thing because they're
easy to remember.  This is a Bad Thing because programmers themselves
may often use generic names for their own modules.


Furthermore, Section 6.12 on the reference documentation says that the
system for importing provides no guarantees, that the import mechanism is
implementation dependent:

    http://www.python.org/doc/current/ref/import.html

It would be nice to have a well-defined, guaranteed way to get at the
Standard Library.


Thanks for the suggestions!




More information about the Python-list mailing list