Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
bd12b181
Kaydet (Commit)
bd12b181
authored
Ock 27, 2004
tarafından
Fred Drake
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
fix whitespace style (inconsistent with the rest of the docs)
üst
fb5a4e33
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
liboptparse.tex
Doc/lib/liboptparse.tex
+17
-17
No files found.
Doc/lib/liboptparse.tex
Dosyayı görüntüle @
bd12b181
...
...
@@ -29,7 +29,7 @@ parser.add_option("-q", "--quiet",
action="store
_
false", dest="verbose", default=True,
help="don't print status messages to stdout")
(options, args)
= parser.parse
_
args()
options, args
= parser.parse
_
args()
\end{verbatim}
With these few lines of code, users of your script can now do the
...
...
@@ -302,7 +302,7 @@ parse it:
\begin{verbatim}
args = ["-f", "foo.txt"]
(options, args)
= parser.parse
_
args(args)
options, args
= parser.parse
_
args(args)
\end{verbatim}
(Note that if you don't pass an argument list to
...
...
@@ -335,7 +335,7 @@ argument right up against the option, since \programopt{-n42} (one
argument) is equivalent to
\programopt
{
-n 42
}
(two arguments).
\begin{verbatim}
(options, args)
= parser.parse
_
args(["-n42"])
options, args
= parser.parse
_
args(["-n42"])
print options.num
\end{verbatim}
...
...
@@ -605,7 +605,7 @@ def main():
parser.add
_
option
(
"
-
q", "
--
quiet",
action
=
"store
_
false", dest
=
"verbose"
)
(
options, args
)
=
parser.parse
_
args
()
options, args
=
parser.parse
_
args
()
if len
(
args
)
!=
1
:
parser.error
(
"incorrect number of arguments"
)
...
...
@@ -1271,7 +1271,7 @@ if you supply \var{callback_args} and/or \var{callback_kwargs} when
you define your callback option
)
, the minimal callback function is:
\begin
{
verbatim
}
def my
_
callback
(
option, opt, value, parser
)
:
def my
_
callback
(
option, opt, value, parser
)
:
pass
\end
{
verbatim
}
...
...
@@ -1291,7 +1291,7 @@ Here's an example of a callback option that takes no arguments, and
simply records that the option was seen:
\begin
{
verbatim
}
def record
_
foo
_
seen
(
option, opt, value, parser
)
:
def record
_
foo
_
seen
(
option, opt, value, parser
)
:
parser.saw
_
foo
=
1
parser.add
_
option
(
"
--
foo", action
=
"callback", callback
=
record
_
foo
_
seen
)
...
...
@@ -1303,7 +1303,7 @@ slightly more interesting example: record the fact that
in the command
-
line.
\begin
{
verbatim
}
def check
_
order
(
option, opt, value, parser
)
:
def check
_
order
(
option, opt, value, parser
)
:
if parser.values.b:
raise OptionValueError
(
"can't use
-
a after
-
b"
)
parser.values.a
=
1
...
...
@@ -1318,7 +1318,7 @@ a bit of work: the error message and the flag that it sets must be
generalized.
\begin
{
verbatim
}
def check
_
order
(
option, opt, value, parser
)
:
def check
_
order
(
option, opt, value, parser
)
:
if parser.values.b:
raise OptionValueError
(
"can't use
%s after -b" % opt)
setattr
(
parser.values, option.dest,
1
)
...
...
@@ -1334,7 +1334,7 @@ you have options that should not be called when the moon is full, all
you have to do is this:
\begin
{
verbatim
}
def check
_
moon
(
option, opt, value, parser
)
:
def check
_
moon
(
option, opt, value, parser
)
:
if is
_
full
_
moon
()
:
raise OptionValueError
(
"
%s option invalid when moon full" % opt)
setattr
(
parser.values, option.dest,
1
)
...
...
@@ -1358,7 +1358,7 @@ argument that must be convertible to that type; if you further define
Here's an example that just emulates the standard ``store'' action:
\begin
{
verbatim
}
def store
_
value
(
option, opt, value, parser
)
:
def store
_
value
(
option, opt, value, parser
)
:
setattr
(
parser.values, option.dest, value
)
...
parser.add
_
option
(
"
--
foo",
...
...
@@ -1405,7 +1405,7 @@ Nevertheless, here's a stab at a callback for an option with variable
arguments:
\begin
{
verbatim
}
def varargs
(
option, opt, value, parser
)
:
def varargs
(
option, opt, value, parser
)
:
assert value is None
done
=
0
value
=
[]
...
...
@@ -1463,8 +1463,8 @@ type-checking functions. A type-checking function has the following
signature:
\begin
{
verbatim
}
def check
_
foo
(
option : Option, opt : string, value : string
)
-
> foo
def check
_
foo
(
option : Option, opt : string, value : string
)
-
> foo
\end
{
verbatim
}
You can name it whatever you like, and make it return any type you
...
...
@@ -1498,7 +1498,7 @@ later (in the \member{TYPE_CHECKER} class attribute of your
\class
{
Option
}
subclass
)
:
\begin
{
verbatim
}
def check
_
complex
(
option, opt, value
)
:
def check
_
complex
(
option, opt, value
)
:
try:
return complex
(
value
)
except ValueError:
...
...
@@ -1509,7 +1509,7 @@ def check_complex (option, opt, value):
Finally, the
\class
{
Option
}
subclass:
\begin
{
verbatim
}
class MyOption
(
Option
)
:
class MyOption
(
Option
)
:
TYPES
=
Option.TYPES
+
(
"complex",
)
TYPE
_
CHECKER
=
copy
(
Option.TYPE
_
CHECKER
)
TYPE
_
CHECKER
[
"complex"
]
=
check
_
complex
...
...
@@ -1600,13 +1600,13 @@ would result in a list:
Again we define a subclass of
\class
{
Option
}
:
\begin
{
verbatim
}
class MyOption
(
Option
)
:
class MyOption
(
Option
)
:
ACTIONS
=
Option.ACTIONS
+
(
"extend",
)
STORE
_
ACTIONS
=
Option.STORE
_
ACTIONS
+
(
"extend",
)
TYPED
_
ACTIONS
=
Option.TYPED
_
ACTIONS
+
(
"extend",
)
def take
_
action
(
self, action, dest, opt, value, values, parser
)
:
def take
_
action
(
self, action, dest, opt, value, values, parser
)
:
if action
==
"extend":
lvalue
=
value.split
(
","
)
values.ensure
_
value
(
dest,
[])
.extend
(
lvalue
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment