Created
July 26, 2010 14:33
-
-
Save bellbind/490613 to your computer and use it in GitHub Desktop.
[python] __import__ by relative module style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def import_as(module_name, globals_): | |
"""__import__ for relative module style. | |
usage: | |
mod = import_as("..templates.jinja2", globals()) | |
# it is same as: import ..templates.jinja2 as mod | |
""" | |
level = 0 | |
for ch in module_name: | |
if ch != ".": break | |
level += 1 | |
pass | |
return __import__(module_name[level:], globals_, locals(), ["*"], level) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment