I would like to understand what is the difference between the two commands
python main.py and main.py to run the main.py file in the command prompt; and which to use in what circumstance.
Justmain.py isn't expected to work unless you have . in the PATH, which is a Very Bad Idea for security reasons. It needs to be ./main.py on a better-configured system. (Also, the .py extension should be present in libraries or modules, not scripts; scripts shouldn't have executables -- same in shell as well)
@sonny, if it starts with #!/usr/bin/env python or another valid shebang, the operating system is charged with starting the executable named in that shebang as an interpreter.
@Wallflower, what operating system are you running? On Windows (but only on Windows), the file extension can be used to automatically select an interpreter. It's on UNIXy systems where scripts shouldn't have extensions and shebangs are used to select interpreters (and also where having . in PATH is considered bad practice; Windows systems haven't been multi-user environments for as long and didn't pick up all the hard-learned lessons from the UNIX world's security experience).
@Wallflower, build a setup.py that uses distutils to install your script, and specify your main function as an entry point; it'll automate creating a script to start your program in whatever way is appropriate for the user's operating system (and it'll also make sure any other Python libraries your script needs are installed).
main.py
isn't expected to work unless you have.
in the PATH, which is a Very Bad Idea for security reasons. It needs to be./main.py
on a better-configured system. (Also, the.py
extension should be present in libraries or modules, not scripts; scripts shouldn't have executables -- same in shell as well)#!/usr/bin/env python
or another valid shebang, the operating system is charged with starting the executable named in that shebang as an interpreter..
inPATH
is considered bad practice; Windows systems haven't been multi-user environments for as long and didn't pick up all the hard-learned lessons from the UNIX world's security experience).setup.py
that uses distutils to install your script, and specify your main function as an entry point; it'll automate creating a script to start your program in whatever way is appropriate for the user's operating system (and it'll also make sure any other Python libraries your script needs are installed).