I want to write a function, so it can be read as a string when using compile()
, but the function has more than one line, so I don't know how to write it.
this is what I want to try to write
def function():
string = "string"
print(string)
new_func = "def function(): string = 'strung' # I don't know how to include the other line here "
new_code = compile(new_func,"",'exec')
eval(new_code)
function()
I would like a way to write the function in just one line (or any other way to format this still using eval()
and compile()