How to execute / call a .py file on the command line?

I wrote a .py file using Eclipse. I want to run this file on the command line. How should I do it? I run it on Windows.

I tried python D: \ Python Work / class / src / hello.py The error I got is python: it is not possible to open the file "D: \ Python": [Errno 2] There is no such file or directory. Also, "D: \ Python" is not the whole address that I specified.

Python has already been added to PATH. I tried to make cd [file directory] and then python file.py, but that gave me the same error

thanks

+4
source share
1 answer

Assuming you are running Windows - either:

python "D:\\Folder name\\Project name\\src\\module name.py" 

Or:

 python "D:/Folder name/Project name/src/module name.py" 

Your choice is basically.

Rules for Windows file names:

Backslashes, \ must be escaped by doubling to \\ must spaces inside double quotes "like this", and some others must be escaped, and the extension does , so give it.

+12
source

Source: https://habr.com/ru/post/1500200/


All Articles