Skip to content

Instantly share code, notes, and snippets.

@ChuckWoodraska
Last active January 9, 2018 20:36
Show Gist options
  • Save ChuckWoodraska/8ab8a64c19f04e955b201d1968fc48e3 to your computer and use it in GitHub Desktop.
Save ChuckWoodraska/8ab8a64c19f04e955b201d1968fc48e3 to your computer and use it in GitHub Desktop.
class HelloWorld():
def print_hello(self):
print('hello')
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()
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