Skip to content

Instantly share code, notes, and snippets.

@pfuntner
Last active April 3, 2018 15:18
Show Gist options
  • Save pfuntner/c86845447d4ddb98edcbfcd85b70a1c8 to your computer and use it in GitHub Desktop.
Save pfuntner/c86845447d4ddb98edcbfcd85b70a1c8 to your computer and use it in GitHub Desktop.
Example usage of dynaloader
#! /usr/bin/python
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__"')
exec(dynaload("pfuntner/toys/master/bin/table.py"))
table = Table(("Column 1", "Column 2"))
table.add(("row 1, cell 1", "row 1, cell 2"))
table.add(("row 2, cell 1", "row 2, cell 2"))
print str(table)
@pfuntner
Copy link
Author

pfuntner commented Apr 3, 2018

This is a complete example of usingmy dynamic loading technique to load a Python script from the public Git server. 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