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

Mats Wichmann mats at wichmann.us
Mon Apr 2 14:01:15 EDT 2018


On 04/02/2018 11:41 AM, eryk sun wrote:
> 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".


so in summary... if you have things set up so you can click-to-launch,
filenames with spaces in them will work, but you'll be better off
avoiding them, esp. if you intend to launch from a command line.




More information about the Tutor mailing list