Sep-25-2017, 02:28 PM
That's some fun script.
To understand the problem you should print variable
To solve the problem convert string to bytes and decode with
To understand the problem you should print variable
c
.You'll see that i = 0\nwhile True:\n\tprint(i)\n\ti += 1
is printed which implies that the backslash has already been escaped. So your real string actually is i = 0\\nwhile True:\\n\\tprint(i)\\n\\ti += 1
.To solve the problem convert string to bytes and decode with
unicode-escape
c = (decode(code)) c = c.encode('ascii').decode('unicode-escape') exec(c)More on problem:
>>> a = 'hello \nThis is newline \n\tThis is horizontal tab' >>> print(a) hello This is newline This is horizontal tab >>> a = 'hello \\nThis is not a newline \\n\\tThis is not a horizontal tab' >>> print(a) hello \nThis is not a newline \n\tThis is not a horizontal tab