[Tutor] running a .py file from the comand line

eryk sun eryksun at gmail.com
Mon Apr 2 13:41:05 EDT 2018


On Mon, Apr 2, 2018 at 8:53 AM, Alan Gauld via Tutor <tutor at python.org> wrote:
>
> Try
>
> python c:\Users\Rex\"ascii keys.py"
>
> Note the quotes to cater for the space.
>
>> python:  can't open file 'Ascii':  [errno2] no such file or directory
>
> The space confuses windows CMD, so it thinks you have
> two files called 'Ascii' and 'keys.py'

Unlike Unix, this is not due to the shell in Windows. A process is
started with a raw command line string. For a C/C++ application, the
default process entry point is provided by the C runtime and does the
setup work to call the application entry point (e.g. [w]main). This
includes parsing the command line into an argv array according to
documented rules [1]. An application can also call GetCommandLineW [2]
and CommandLineToArgvW [3].

[1]: https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments
[2]: https://msdn.microsoft.com/en-us/library/ms683156
[3]: https://msdn.microsoft.com/en-us/library/bb776391

CPython is written in C and uses the standard Windows C/C++ wmain and
wWinMain application entry points. If you run "python
C:\Users\Rex\Ascii Keys.py", the C runtime parses this into an argv
array with 3 items: "python", "C:\Users\Rex\Ascii", and "Keys.py".
Thus Python tries to open a script named "C:\Users\Rex\Ascii".


More information about the Tutor mailing list