I have ran into a problem with a project I'm working on. I've found where in the code this problem is happening, and put it in an isolated, simple environment, and the error persists.
Here's the code:
def parse(input_var):
input_var = input_var.split("[METHOD]")
if(len(input_var)>1):
input_var[0] = input_var[0].replace("using ","exec(parse(")
input_var[0] = input_var[0].replace(";","))")
input_var = input_var[0]+input_var[1]
else:
input_var=input_var[0]
exec(input_var)
foo="""
using bar;
[METHOD]
print('Passed foo!')
"""
bar = """
print('Passed bar!')
"""
parse(foo)
And here is the output from running the code:
Passed bar!
Traceback (most recent call last):
File "python", line 22, in <module>
File "python", line 9, in parse
File "<string>", line 2, in <module>
TypeError: exec() arg 1 must be a string, bytes or code object
The "bar" piece of code is causing the problem, even though it obviously is a string. The thing that's so rotten about this is that it never runs the second half of the "foo" code, which in my other program that uses this code, is kind of necessary.
input_varafter each line inside if block ?