I write a python code generator
as an input it has a source code: source
Part of the output I need to generate is execute(source_code)
When source_code is a string representing source .
If I write "execute({0})".format(source) for input source = "import sys"
i'll get execute(import sys).
So I tried : execute(\"\"\"{0}\"\"\")format(source). Is it ok? I tried to test it...Sometimes it is ok....The problem occurs when inside the source there are"""
For example:
from IPython.display import HTML
HTML("""
<script>
console.log("hello");
</script>
<b>HTML</b>
""")
my code turns to be
execute("""from IPython.display import HTML
HTML("""
<script>
console.log("hello");
</script>
<b>HTML</b>
""")""")
UPD: Changing the code to
execute('''{0}''').format(source)
doesn`t solve the problem, the issue will be encountered with :
def tojson(data):
'''Shorten the code to respond a little bit.'''
print(json.dumps(data))