__std__: a namespace for the Standard Library

From the README:

Packaged by Danny Yoo with suggestions from Bengt Richter, Just van Rossum, Robin Becker, Terry Hancock, and Andrew Bennetts from comp.lang.python. For the historical record, here's a link to the discussion.

(2006/04/19) Recently, I found that Holger Krekel has done something similar with the py.std library, and that Python 2.5's PEP 328 will fix this once and for all. Hurrah! So my own library is deprecated now, but for posterity, I'll leave it here.

If you're using Python 2.5, use the from __future__ import absolute_import functionality.


__std__ provides a standard namespace that we can use to import libraries from the Standard Library, regardless of what current directory we're in. The __std__ module provides the programmer consistant access to the Standard Library without having to worry as much about module path problems.

As a concrete example, say that we're experimenting with the random module, and by accident, we name our testing program random.py. We can't just say:

import random
print random.randrange(42)
because we would be importing our own custom 'random' rather than the one in the Standard Library --- we'd end up with the error message:
[dyoo@tesuque dyoo]$ python random.py
Traceback (most recent call last):
  File "random.py", line 1, in ?
    import random
  File "random.py", line 2, in ?
    print random.randrange(42)
AttributeError: 'module' object has no attribute 'randrange'

No problem: this is what __std__ is meant to solve. We can still get at the Standard Library module like this:

###
### random.py
###
from __std__ import random
print random.randrange(42)

Releases

Back to python.