Created
March 26, 2018 17:39
-
-
Save pfuntner/b842370be0026279d02f4d812a8bf43d to your computer and use it in GitHub Desktop.
Dynamic loader for Python code
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
""" | |
import sys | |
import requests | |
""" | |
def dynaload(path): | |
url = "https://raw.githubusercontent.com/{path}".format(**locals()) | |
req = requests.get(url) | |
if req.status_code != 200: | |
sys.stderr.write("Error loading {url}:\n".format(**locals())) | |
for name in vars(req): | |
value = getattr(req, name) | |
sys.stderr.write(" {name}: {value}\n".format(**locals())) | |
exit(1) | |
return req.text.replace('"__main__"', '"__static_main__"') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This snippet is an example of a function to carry out my dynamic loading technique. See my Dynamic Python script loading blog article for more details.