mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-13826: Clarify Popen constructor example (GH-18438)
Clarifies that the use of `shlex.split` is more instructive than normative, and provides a simpler example. https://bugs.python.org/issue13826
This commit is contained in:
parent
37c55b2b49
commit
95d024d585
1 changed files with 8 additions and 2 deletions
|
@ -356,14 +356,20 @@ functions.
|
||||||
arguments for additional differences from the default behavior. Unless
|
arguments for additional differences from the default behavior. Unless
|
||||||
otherwise stated, it is recommended to pass *args* as a sequence.
|
otherwise stated, it is recommended to pass *args* as a sequence.
|
||||||
|
|
||||||
|
An example of passing some arguments to an external program
|
||||||
|
as a sequence is::
|
||||||
|
|
||||||
|
Popen(["/usr/bin/git", "commit", "-m", "Fixes a bug."])
|
||||||
|
|
||||||
On POSIX, if *args* is a string, the string is interpreted as the name or
|
On POSIX, if *args* is a string, the string is interpreted as the name or
|
||||||
path of the program to execute. However, this can only be done if not
|
path of the program to execute. However, this can only be done if not
|
||||||
passing arguments to the program.
|
passing arguments to the program.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
:meth:`shlex.split` can be useful when determining the correct
|
It may not be obvious how to break a shell command into a sequence of arguments,
|
||||||
tokenization for *args*, especially in complex cases::
|
especially in complex cases. :meth:`shlex.split` can illustrate how to
|
||||||
|
determine the correct tokenization for *args*::
|
||||||
|
|
||||||
>>> import shlex, subprocess
|
>>> import shlex, subprocess
|
||||||
>>> command_line = input()
|
>>> command_line = input()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue