Issue
I have this python code
while 1:
exec(input())
when I enter import os \nos.system("echo 1")
I get this error
File "<string>", line 1
import os \nos.system("echo 1")
^
SyntaxError: unexpected character after line continuation character
Solution
The problem is that you're using \n
within the exec
, which as @The Thonnu mentioned causes problems when parsing.
Try entering import os; os.system("echo 1")
instead.
Semicolons can be used in Python to separate different lines as an alternative to semicolons.
If you must use \n
in your input, you can also use:
while 1:
exec(input().replace('\\n', '\n'))
Answered By - Krishnan Shankar Answer Checked By - Willingham (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.