-
-
Notifications
You must be signed in to change notification settings - Fork 32k
timeit basic examples are not compatible for Windows (CMD/ PowerShell) #106232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
both the examples worked for me in PowerShell 7.3.4. What version of PowerShell did you try it with? |
PS Version 5.1.19041.3031
|
Yes I just tested it on another machine, on Powershell v5.1 its not working but works on v7.3 |
Newer versions of PowerShell rewrite a command line that contains a single-quoted string to instead use double quotes, with literal double quote characters backslash escaped as needed. For example, In contrast, the CMD shell has no special handling of single quote characters in this context. It passes the command line exactly as written to the spawned process. The C runtime in the spawned Python process has no special handling of single quote characters when parsing a command line into an argument array. For example, Also, most Python installations on Windows have no "python3" command. The exception, at least for official PSF releases, is the app distribution in the Microsoft Store, which enables a "python3.exe" appexec alias by default. |
Examples should use the generic 'python' and work on Windows Command Prompt. People should substitute 'python' with 'python3', 'python3.y', 'py', 'py -3', 'py -3.y'. I presume " outside ' works on *nix. Working on PR. |
Command Prompt (CMD Shell) and older versions of PowerShell require double quotes and single quotes inside the string. This form also works on linux and macOS.
…06296) Command Prompt (CMD Shell) and older versions of PowerShell require double quotes and single quotes inside the string. This form also works on linux and macOS.
…s. (pythonGH-106296) Command Prompt (CMD Shell) and older versions of PowerShell require double quotes and single quotes inside the string. This form also works on linux and macOS. (cherry picked from commit 04dfc6f) Co-authored-by: Terry Jan Reedy <[email protected]>
…ws. (GH-106296) (#106298) gh-106232: Make timeit doc command lines compatible with Windows. (GH-106296) Command Prompt (CMD Shell) and older versions of PowerShell require double quotes and single quotes inside the string. This form also works on linux and macOS. (cherry picked from commit 04dfc6f) Co-authored-by: Terry Jan Reedy <[email protected]>
Main already has 'python', not 'python3'. However, 'python' was 'python3' in 3.11, changed in 3.12. Hence a backport would require redoing the patch. |
…s. (python#106296) Command Prompt (CMD Shell) and older versions of PowerShell require double quotes and single quotes inside the string. This form also works on linux and macOS.
Documentation
on this page
https://docs.python.org/3/library/timeit.html
the example
python3 -m timeit '"-".join(str(n) for n in range(100))'
should be
python3 -m timeit "'-'.join(str(n) for n in range(100))"
because CMD and PowerShell do not support the first format
Linked PRs
The text was updated successfully, but these errors were encountered: