changeset 69 | c6bca38c1cbf |
68:5ff1fc726848 | 69:c6bca38c1cbf |
---|---|
1 import sys |
|
2 |
|
3 class Std(object): |
|
4 """ makes top-level python modules available as an attribute, |
|
5 importing them on first access. |
|
6 """ |
|
7 |
|
8 def __init__(self): |
|
9 self.__dict__ = sys.modules |
|
10 |
|
11 def __getattr__(self, name): |
|
12 try: |
|
13 m = __import__(name) |
|
14 except ImportError: |
|
15 raise AttributeError("py.std: could not import %s" % name) |
|
16 return m |
|
17 |
|
18 std = Std() |