This is my test code, test.py:
str = input("IP: ")
print(str)
When running I get this error:
➜ PingScript git:(master) ✗ python test.py
IP: 1.1.1.1
Traceback (most recent call last):
File "test.py", line 1, in <module>
str = input("IP: ")
File "<string>", line 1
1.1.1.1
^
SyntaxError: invalid syntax
This happens only if I use 1.1.1.1 as input and not if I use 1.1 as input, what is happening here? I’ve tried to parse it with str(str) but I still get the same error.
input()tries to parse the input as a python expression. Useraw_input()instead.It works with
1.1as input because that’s a literal float value, a number, in python.It could be that you are following a tutorial meant for Python 3, but are using Python 2 instead. In Python 3, the
raw_input()function was renamed toinput()and the oldinput()function was removed altogether. If so, please install Python 3 and continue from there.