Last active
January 9, 2018 20:36
-
-
Save ChuckWoodraska/8ab8a64c19f04e955b201d1968fc48e3 to your computer and use it in GitHub Desktop.
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
class HelloWorld(): | |
def print_hello(self): | |
print('hello') |
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 requests | |
import json | |
import tempfile | |
from importlib.machinery import SourceFileLoader | |
fp = tempfile.NamedTemporaryFile(suffix='.py') | |
response = requests.get('http://127.0.0.1:5002/python_script') | |
print(response.text) | |
# { | |
# "hello": "class HelloWorld():\n def print_hello(self):\n print('hello')\n\nclass HelloWorld2():\n def print_hello(self):\n print('hello')" | |
# } | |
fp.write(json.loads(response.text).get('data').encode()) | |
fp.seek(0) | |
print(fp.name) | |
ig = SourceFileLoader("ig", fp.name).load_module() | |
print(dir(ig)) | |
ig.HelloWorld().print_hello() |
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
from flask import Flask, jsonify | |
app = Flask(__name__) | |
@app.route('/python_script') | |
def python_script(): | |
return jsonify({'data': open('proto.py', 'r').read()}) | |
if __name__ == '__main__': | |
app.run(debug=True, port=5002) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment