Python syntax error near unexpected token
Question:
I checked several duplicate questions, but they are not related to python.
This is my script
#/bin/python3
import time
# Get the today date and use it as folder name
print(time.strftime("%Y-%m-%d"))
as soon as I try to use it form the terminal (bash shell), I get the syntax error.
./test.py: line 5: syntax error near unexpected token `time.strftime'
./test.py: line 5: `print(time.strftime("%Y-%m-%d"))'
Looking at the code nothing seems to be wrong, and I’m not getting which one is the problem and if it’s related to Python or to Linux (as in other posts seems it can depends from linux too).
Answers:
You’re missing the !
in the first line, so it’s just a comment and the whole thing is being interpreted as a sh script. It should look like this:
#!/bin/python3
Change first string to something like #!/usr/bin/python3
You should use #!
instead of #
.
why is this line necessary?
#/bin/python3
i was running python scripts without it no problem
using linux mint
I checked several duplicate questions, but they are not related to python.
This is my script
#/bin/python3
import time
# Get the today date and use it as folder name
print(time.strftime("%Y-%m-%d"))
as soon as I try to use it form the terminal (bash shell), I get the syntax error.
./test.py: line 5: syntax error near unexpected token `time.strftime'
./test.py: line 5: `print(time.strftime("%Y-%m-%d"))'
Looking at the code nothing seems to be wrong, and I’m not getting which one is the problem and if it’s related to Python or to Linux (as in other posts seems it can depends from linux too).
You’re missing the !
in the first line, so it’s just a comment and the whole thing is being interpreted as a sh script. It should look like this:
#!/bin/python3
Change first string to something like #!/usr/bin/python3
You should use #!
instead of #
.
why is this line necessary?
#/bin/python3
i was running python scripts without it no problem
using linux mint