class / module introspection?
Brian Munroe
brian.e.munroe at gmail.com
Wed Apr 2 15:07:46 EDT 2008
On Apr 2, 11:04 am, "bruno.desthuilli... at gmail.com"
<bruno.desthuilli... at gmail.com> wrote:
>
> More seriously: the answer is in the doc.http://www.python.org/doc/2.3.5/lib/built-in-funcs.html
>
> read about the __import__ function, experiment in your interactive
> python shell, and you should be done in a couple minutes.
Well, If I understand the docs correctly, that would work great if
backends/ was a module and not a package? I need to keep backends/
system1/ and backends/system2 as separate directory structures to make
things fairly isolated from each other (for neatness sake)
Currently I'm building the backends/__init__.py __all__ list
dynamically, such as:
backends/__init__.py
--------------------
import os
__all__ = []
for module in os.listdir(__path__[0]):
if not module.startswith("__"):
__all__.append(module)
then from my main application, I can do the following
main.py
-------
import backends
print backends.__all__
This gives me ['system1','system2'] - which I can then use __import__
on.
-- brian
More information about the Python-list
mailing list