0

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).

3
  • 2
    This exact code works just fine for me, maybe it has something to do with some obscure symbol in your file or file encoding? Commented Dec 15, 2016 at 15:53
  • I just found it.. the problem was in the first line.. It's missing the ! after the #. Commented Dec 15, 2016 at 15:53
  • What does this have to do with bash, removing the tag on that note. Commented Dec 15, 2016 at 17:02

2 Answers 2

7

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
Sign up to request clarification or add additional context in comments.

Comments

0

Change first string to something like #!/usr/bin/python3

You should use #! instead of #.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.