mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[Bug #688261] Fix optparse example and output
This commit is contained in:
parent
acddabc6ec
commit
7ee9b51ba5
1 changed files with 5 additions and 2 deletions
|
@ -1735,6 +1735,7 @@ You start by creating an instance of \class{OptionParser} and telling
|
||||||
it what your program's options are.
|
it what your program's options are.
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
|
import sys
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
op = OptionParser()
|
op = OptionParser()
|
||||||
|
@ -1750,7 +1751,9 @@ Parsing a command line is then done by calling the \method{parse_args()}
|
||||||
method.
|
method.
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
options, args = op.parse_args(sys.argv[1:])
|
import optparse
|
||||||
|
|
||||||
|
options, args = optparse.parse_args(sys.argv[1:])
|
||||||
print options
|
print options
|
||||||
print args
|
print args
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
@ -1768,7 +1771,7 @@ $ ./python opt.py -i data arg1
|
||||||
['arg1']
|
['arg1']
|
||||||
$ ./python opt.py --input=data --length=4
|
$ ./python opt.py --input=data --length=4
|
||||||
<Values at 0x400cad2c: {'input': 'data', 'length': 4}>
|
<Values at 0x400cad2c: {'input': 'data', 'length': 4}>
|
||||||
['arg1']
|
[]
|
||||||
$
|
$
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue