Having a __stdlib__ namespace?

Terry Hancock hancock at anansispaceworks.com
Fri Jan 10 04:29:16 EST 2003


Daniel Yoo wrote:
> 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

> 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.

Of course, on Unix/Linux you can put a symlink in to name it:

% cd /usr/lib/python2.2/
% ln -s /usr/lib/python2.2/ /usr/lib/python2.2/__stdlib__
% touch __init__.py

% cd ~
% python
Python 2.2.1 (#1, Sep  7 2002, 14:34:30) 
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import __stdlib__
>>> from __stdlib__ import string
>>> dir(string)
['_StringType', '__builtins__', '__doc__', '__file__', '__name__',  
                        ....

So that works.  I don't know an equivalent solution for Windows (or any OS 
lacking symlinks).  Looks kind of sinful to me, but I suppose it could work.

Terry

-- 
Anansi Spaceworks
http://www.anansispaceworks.com




More information about the Python-list mailing list