Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are py and python giving different results?

Using py and python are giving me different results in the Command Prompt. For my specific program, when I run python file.py, the program works as expected. However, when I run py file.py, it gives me this error:

  File "wordcount.py", line 60
print(f"{wordlist[num]} {wordcount[num]}")
                                        ^

SyntaxError: invalid syntax

Can anyone tell me why python works and not py?

EDIT: I should clarify, I've already checked the system. Typing py gives me Python 3.8.3, which means that the 2.x explanation doesn't match my case. import sys going into print(sys.version) gives me the same results.

like image 203
Jwee Avatar asked Jan 01 '23 00:01

Jwee


1 Answers

Probably py is set to Python 2 and python is set to Python 3 on your system.

Try checking the versions with python --version and py --version respectively.

It's not working with Python 2 since your code uses f-Strings, which where added in Python 3.6.

like image 82
capek Avatar answered Jan 14 '23 22:01

capek