Skip to content

Instantly share code, notes, and snippets.

@Sourceless
Last active December 20, 2015 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sourceless/6065182 to your computer and use it in GitHub Desktop.
Save Sourceless/6065182 to your computer and use it in GitHub Desktop.
Stupidly bad python function importy thing
# 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