Last active
April 3, 2018 15:18
-
-
Save pfuntner/c86845447d4ddb98edcbfcd85b70a1c8 to your computer and use it in GitHub Desktop.
Example usage of dynaloader
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
#! /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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.