This code works fine when I run it in my PyCharm IDE…
argnotparse.py
if __name__ == '__main__':
print('Hello world')
world = 'world'
print(f'Hello {world}')
print('Hello', 'world', sep=' ', end='\n')
It produces the expected output of…
argnotparse.py"
Hello world
Hello world
Hello world
but if I run it from the command line I see…
$ python argnotparse.py
File "argnotparse.py", line 5
print(f'Hello {world}')
^
SyntaxError: invalid syntax
My first thought was that something in python's command line parser wasn't updated with the f-strings in python v3.6. So I commented that line out and tried again…
$ python argnotparse.py
File "argnotparse.py", line 6
print('Hello', 'world', sep=' ', end='\n')
^
SyntaxError: invalid syntax
This ruled out my idea that the argparse module had not been updated as its tutorial demonstrates this python v3 print statement with 'end' as a parameter. (It's in the section titled 'Getting a little more advanced'.)
Why is this happening?
p.s. I'm running python 3.7
--edit--