I am using compile with exec to execute a python code specified by user. Below are 2 cases reprsenting the usert code that needs to be compiled. The user code is read into a string and then compiled as shown below. The compile works fine for case 1 while it throws a syntax error - "SyntaxError: unexpected character after line continuation character" for case 2
case 1 (works):
if len([1,2]) == 2:
return True
elif len([1,2]) ==3:
return False
case 2 (fails):
if len([1,2]) == 2:\n return True\n elif len([1,2]) ==3:\n return False
compiled as:
compile(userCde, '<string>','exec')
Any ideas?? Thanks!!