Skip to content

Instantly share code, notes, and snippets.

@pfuntner
Created March 26, 2018 17:39
Show Gist options
  • Save pfuntner/b842370be0026279d02f4d812a8bf43d to your computer and use it in GitHub Desktop.
Save pfuntner/b842370be0026279d02f4d812a8bf43d to your computer and use it in GitHub Desktop.
Dynamic loader for Python code
"""
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__"')
@pfuntner
Copy link
Author

pfuntner commented Apr 3, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment