Last active
December 20, 2015 03:39
-
-
Save Sourceless/6065182 to your computer and use it in GitHub Desktop.
Stupidly bad python function importy thing
This file contains 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
# Disclaimer: this is terrible and bad. | |
# Directory structure: | |
# bin/ | |
# fragman/ | |
# __init__.py | |
# fragments/ | |
# __init__.py | |
# some_awesome_func.py | |
# | |
# | |
# Usage, in the interpreter... | |
# >>> import fragman | |
# >>> fragman.pull('some_awesome_func') | |
# >>> fragman.some_awesome_func(5) | |
# 5 | |
# ... | |
### some_awesome_func.py ### | |
def some_awesome_func(x): | |
return x | |
### __init__.py ### | |
#!/usr/bin/env python | |
import json | |
import importlib | |
import os.path | |
def pull(*fragments): | |
for fragment in fragments: | |
# In reality you'd get it from the package list... | |
frag_path = "fragman.fragments." + fragment | |
temp = __import__(frag_path, globals(), locals(), [fragment]) | |
shard = temp.__dict__[fragment] | |
globals()[fragment] = shard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment