Python imports by folder module
Posted
by colinmarc
on Stack Overflow
See other posts from Stack Overflow
or by colinmarc
Published on 2010-06-12T01:05:59Z
Indexed on
2010/06/12
1:12 UTC
Read the original article
Hit count: 284
I have a directory structure:
example.py
templates/
__init__.py
a.py
b.py
a.py
and b.py
have only one class, named the same as the file (because they are cheetah templates). For purely style reasons, I want to be able to import and use these classes in example.py
like so:
import templates
t = templates.a()
Right now I do that by having this in the template folder's __init__.py
:
__all__ = ["a", "b"]
from . import *
However, this seems pretty poor (and maybe superfluous), and doesn't even do what I want, as I have to use the classes like this:
t = templates.a.a()
Thoughts?
© Stack Overflow or respective owner