chunk_id stringlengths 36 36 | source stringclasses 35
values | source_url stringlengths 0 290 | upstream_license stringclasses 1
value | document_id stringlengths 36 36 | chunk_index int64 0 324k | retrieved_at stringclasses 2
values | chunker_version stringclasses 4
values | content_hash stringlengths 15 64 | content stringlengths 50 44.7k | namespace stringclasses 9
values | source_name stringclasses 35
values | raw_text stringlengths 50 44.7k | cleaned_text stringlengths 50 44.7k | tags stringclasses 49
values | collection_name stringclasses 11
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
9dbbd0d9-bb39-4938-8be1-9c47bfcce3e7 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,074 | supabase-export-v2 | 52566866bc9c1dbf | pass class B(O): pass class C(O): pass class D(O): pass class E(O): pass class K1(A,B,C): pass class K2(D,B,E): pass class K3(D,A): pass class Z(K1,K2,K3): pass
def merge(seqs):
print '\n\nCPL[%s]=%s' % (seqs[0][0],seqs),
res = []; i=0
while 1:
nonemptyseqs=[seq for seq in seqs if seq]
if not nonemptyseqs: return ... | trusted_official_docs | CPython Docs | pass class B(O): pass class C(O): pass class D(O): pass class E(O): pass class K1(A,B,C): pass class K2(D,B,E): pass class K3(D,A): pass class Z(K1,K2,K3): pass
def merge(seqs):
print '\n\nCPL[%s]=%s' % (seqs[0][0],seqs),
res = []; i=0
while 1:
nonemptyseqs=[seq for seq in seqs if seq]
if not nonemptyseqs: return ... | pass class B(O): pass class C(O): pass class D(O): pass class E(O): pass class K1(A,B,C): pass class K2(D,B,E): pass class K3(D,A): pass class Z(K1,K2,K3): pass
def merge(seqs):
print '\n\nCPL[%s]=%s' % (seqs[0][0],seqs),
res = []; i=0
while 1:
nonemptyseqs=[seq for seq in seqs if seq]
if not nonemptyseqs: return ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a204141c-8f79-47c7-baf3-5f2c83445d93 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 57,997 | supabase-export-v2 | cf34172a97224737 | | C | 2 | --- --- | \ / | \ / \ / --- Level 0 0 | A | (more specialized) ---
The linearizations of O,D,E and F are trivial:: | trusted_official_docs | CPython Docs | | C | 2 | --- --- | \ / | \ / \ / --- Level 0 0 | A | (more specialized) ---
The linearizations of O,D,E and F are trivial:: | | C | 2 | --- --- | \ / | \ / \ / --- Level 0 0 | A | (more specialized) ---
The linearizations of O,D,E and F are trivial:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a3169727-b8bc-44b9-b673-3631c1e58db4 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,019 | supabase-export-v2 | 838a1699178e6e2c | L[O] = 0 L[X] = X O L[Y] = Y O L[A] = A X Y O L[B] = B Y X O
However, it is impossible to compute the linearization for a class C
that inherits from A and B:: | trusted_official_docs | CPython Docs | L[O] = 0 L[X] = X O L[Y] = Y O L[A] = A X Y O L[B] = B Y X O
However, it is impossible to compute the linearization for a class C
that inherits from A and B:: | L[O] = 0 L[X] = X O L[Y] = Y O L[A] = A X Y O L[B] = B Y X O
However, it is impossible to compute the linearization for a class C
that inherits from A and B:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b0529de9-047f-43ad-9c36-b14ee9f6eb48 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,061 | supabase-export-v2 | 92196dc02c42900e | Here are the linearizations according to the C3 MRO (the reader should verify these linearizations as an exercise and draw the inheritance diagram ;-) ::
L[A] = A O
L[B] = B O
L[C] = C O
L[D] = D O
L[E] = E O
L[K1]= K1 A B C O
L[K2]= K2 D B E O
L[K3]= K3 D A O
L[Z] = Z K1 K2 K3 D A B C E O | trusted_official_docs | CPython Docs | Here are the linearizations according to the C3 MRO (the reader should verify these linearizations as an exercise and draw the inheritance diagram ;-) ::
L[A] = A O
L[B] = B O
L[C] = C O
L[D] = D O
L[E] = E O
L[K1]= K1 A B C O
L[K2]= K2 D B E O
L[K3]= K3 D A O
L[Z] = Z K1 K2 K3 D A B C E O | Here are the linearizations according to the C3 MRO (the reader should verify these linearizations as an exercise and draw the inheritance diagram ;-) ::
L[A] = A O
L[B] = B O
L[C] = C O
L[D] = D O
L[E] = E O
L[K1]= K1 A B C O
L[K2]= K2 D B E O
L[K3]= K3 D A O
L[Z] = Z K1 K2 K3 D A B C E O | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b184ce19-1aed-48ae-a0fc-72280483f0d1 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 57,957 | supabase-export-v2 | 413a23f9c27864f5 | class C, including the class itself, ordered from the nearest ancestor to the furthest, is called the class precedence list or the *linearization* of C.
3) The *Method Resolution Order* (MRO) is the set of rules that
construct the linearization. In the Python literature, the idiom
"the MRO of C" is also used as a syn... | trusted_official_docs | CPython Docs | class C, including the class itself, ordered from the nearest ancestor to the furthest, is called the class precedence list or the *linearization* of C.
3) The *Method Resolution Order* (MRO) is the set of rules that
construct the linearization. In the Python literature, the idiom
"the MRO of C" is also used as a syn... | class C, including the class itself, ordered from the nearest ancestor to the furthest, is called the class precedence list or the *linearization* of C.
3) The *Method Resolution Order* (MRO) is the set of rules that
construct the linearization. In the Python literature, the idiom
"the MRO of C" is also used as a syn... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b32aa31d-eceb-4b79-94e9-114b50681cb0 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,025 | supabase-export-v2 | 49da72813c6b182e | It is easier to start with the local precedence ordering. Consider the following example:
>>> F=type('Food',(),{'remember2buy':'spam'})
>>> E=type('Eggs',(F,),{'remember2buy':'eggs'})
>>> G=type('GoodFood',(F,E),{}) # under Python 2.3 this is an error! # doctest: +SKIP | trusted_official_docs | CPython Docs | It is easier to start with the local precedence ordering. Consider the following example:
>>> F=type('Food',(),{'remember2buy':'spam'})
>>> E=type('Eggs',(F,),{'remember2buy':'eggs'})
>>> G=type('GoodFood',(F,E),{}) # under Python 2.3 this is an error! # doctest: +SKIP | It is easier to start with the local precedence ordering. Consider the following example:
>>> F=type('Food',(),{'remember2buy':'spam'})
>>> E=type('Eggs',(F,),{'remember2buy':'eggs'})
>>> G=type('GoodFood',(F,E),{}) # under Python 2.3 this is an error! # doctest: +SKIP | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b3558dbd-5cd4-4a3c-8f60-2cb11c818f66 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 57,954 | supabase-export-v2 | 626638dbe9bc39b1 | know how multiple inheritance works, then this paper is for you. The good news is that things are not as complicated as you might expect.
Let me begin with some basic definitions. | trusted_official_docs | CPython Docs | know how multiple inheritance works, then this paper is for you. The good news is that things are not as complicated as you might expect.
Let me begin with some basic definitions. | know how multiple inheritance works, then this paper is for you. The good news is that things are not as complicated as you might expect.
Let me begin with some basic definitions. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b40ba1a9-5b49-4986-aef6-9d4dd3698482 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,064 | supabase-export-v2 | 6e04dc969ca6147e | L[Z,P22] = Z K1 K3 A K2 D B C E O
It is clear that this linearization is *wrong*, since A comes before D
whereas in the linearization of K3 A comes *after* D. In other words, in
K3 methods derived by D override methods derived by A, but in Z, which
still is a subclass of K3, methods derived by A override methods derive... | trusted_official_docs | CPython Docs | L[Z,P22] = Z K1 K3 A K2 D B C E O
It is clear that this linearization is *wrong*, since A comes before D
whereas in the linearization of K3 A comes *after* D. In other words, in
K3 methods derived by D override methods derived by A, but in Z, which
still is a subclass of K3, methods derived by A override methods derive... | L[Z,P22] = Z K1 K3 A K2 D B C E O
It is clear that this linearization is *wrong*, since A comes before D
whereas in the linearization of K3 A comes *after* D. In other words, in
K3 methods derived by D override methods derived by A, but in Z, which
still is a subclass of K3, methods derived by A override methods derive... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b7b57d21-5e77-4712-baf8-2c83bed89eb1 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,021 | supabase-export-v2 | ff476d9db4438823 | L[C] = C + merge(AXYO, BYXO, AB) = C + A + merge(XYO, BYXO, B) = C + A + B + merge(XYO, YXO)
At this point we cannot merge the lists XYO and YXO, since X is in the
tail of YXO whereas Y is in the tail of XYO: therefore there are no
good heads and the C3 algorithm stops. Python 2.3 raises an error and
refuses to create ... | trusted_official_docs | CPython Docs | L[C] = C + merge(AXYO, BYXO, AB) = C + A + merge(XYO, BYXO, B) = C + A + B + merge(XYO, YXO)
At this point we cannot merge the lists XYO and YXO, since X is in the
tail of YXO whereas Y is in the tail of XYO: therefore there are no
good heads and the C3 algorithm stops. Python 2.3 raises an error and
refuses to create ... | L[C] = C + merge(AXYO, BYXO, AB) = C + A + merge(XYO, BYXO, B) = C + A + B + merge(XYO, YXO)
At this point we cannot merge the lists XYO and YXO, since X is in the
tail of YXO whereas Y is in the tail of XYO: therefore there are no
good heads and the C3 algorithm stops. Python 2.3 raises an error and
refuses to create ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ba7bb959-7795-47e1-a8c0-42f4b4f3f399 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 57,943 | supabase-export-v2 | 268dec570e1329ea | :Abstract:
*This document is intended for Python programmers who want to
understand the C3 Method Resolution Order used in Python 2.3. Although it is not intended for newbies, it is quite pedagogical with
many worked out examples. I am not aware of other publicly available
documents with the same scope, therefore it... | trusted_official_docs | CPython Docs | :Abstract:
*This document is intended for Python programmers who want to
understand the C3 Method Resolution Order used in Python 2.3. Although it is not intended for newbies, it is quite pedagogical with
many worked out examples. I am not aware of other publicly available
documents with the same scope, therefore it... | :Abstract:
*This document is intended for Python programmers who want to
understand the C3 Method Resolution Order used in Python 2.3. Although it is not intended for newbies, it is quite pedagogical with
many worked out examples. I am not aware of other publicly available
documents with the same scope, therefore it... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bb217fde-62bb-49e9-bd33-2bdfabfca083 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,059 | supabase-export-v2 | a42b3cd58ecc9dfd | 2.2 makes breaking monotonicity difficult, but not impossible. The following example, originally provided by Samuele Pedroni, shows that the MRO of Python 2.2 is non-monotonic:
>>> class A(object): pass
>>> class B(object): pass
>>> class C(object): pass
>>> class D(object): pass
>>> class E(object): pass
>>> clas... | trusted_official_docs | CPython Docs | 2.2 makes breaking monotonicity difficult, but not impossible. The following example, originally provided by Samuele Pedroni, shows that the MRO of Python 2.2 is non-monotonic:
>>> class A(object): pass
>>> class B(object): pass
>>> class C(object): pass
>>> class D(object): pass
>>> class E(object): pass
>>> clas... | 2.2 makes breaking monotonicity difficult, but not impossible. The following example, originally provided by Samuele Pedroni, shows that the MRO of Python 2.2 is non-monotonic:
>>> class A(object): pass
>>> class B(object): pass
>>> class C(object): pass
>>> class D(object): pass
>>> class E(object): pass
>>> clas... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bb8605ed-b78e-452e-8ad8-df38c0e6a1e4 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,007 | supabase-export-v2 | f4beb66a032fe707 | E + merge(O,FO) = A + B + C + D + E + F + merge(O,O) = A B C D E F O
In this example, the linearization is ordered in a pretty nice way
according to the inheritance level, in the sense that lower levels (i.e. more specialized classes) have higher precedence (see the inheritance
graph). However, this is not the general ... | trusted_official_docs | CPython Docs | E + merge(O,FO) = A + B + C + D + E + F + merge(O,O) = A B C D E F O
In this example, the linearization is ordered in a pretty nice way
according to the inheritance level, in the sense that lower levels (i.e. more specialized classes) have higher precedence (see the inheritance
graph). However, this is not the general ... | E + merge(O,FO) = A + B + C + D + E + F + merge(O,O) = A B C D E F O
In this example, the linearization is ordered in a pretty nice way
according to the inheritance level, in the sense that lower levels (i.e. more specialized classes) have higher precedence (see the inheritance
graph). However, this is not the general ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bc667430-9416-44d0-8edd-148eb5efb624 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 57,962 | supabase-export-v2 | c5ddfae0e4a08a5a | Here I give an example of this situation. Consider the hierarchy
>>> O = object
>>> class X(O): pass
>>> class Y(O): pass
>>> class A(X,Y): pass
>>> class B(Y,X): pass | trusted_official_docs | CPython Docs | Here I give an example of this situation. Consider the hierarchy
>>> O = object
>>> class X(O): pass
>>> class Y(O): pass
>>> class A(X,Y): pass
>>> class B(Y,X): pass | Here I give an example of this situation. Consider the hierarchy
>>> O = object
>>> class X(O): pass
>>> class Y(O): pass
>>> class A(X,Y): pass
>>> class B(Y,X): pass | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c40cea67-fa94-4a9e-a2d4-36efd768f595 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,002 | supabase-export-v2 | a9d0e053e6eb887b | next sequence. Then we see that E is a good head; we take it and we are reduced to compute ``merge(O,O)`` which gives O. Therefore::
L[B] = B D E O | trusted_official_docs | CPython Docs | next sequence. Then we see that E is a good head; we take it and we are reduced to compute ``merge(O,O)`` which gives O. Therefore::
L[B] = B D E O | next sequence. Then we see that E is a good head; we take it and we are reduced to compute ``merge(O,O)`` which gives O. Therefore::
L[B] = B D E O | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c7da390e-8014-43d6-8243-2ae1cf5d7d3e | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,004 | supabase-export-v2 | a500ebe8fe20c6c1 | Using the same procedure one finds::
L[C] = C + merge(DO,FO,DF)
= C + D + merge(O,FO,F)
= C + D + F + merge(O,O)
= C D F O | trusted_official_docs | CPython Docs | Using the same procedure one finds::
L[C] = C + merge(DO,FO,DF)
= C + D + merge(O,FO,F)
= C + D + F + merge(O,O)
= C D F O | Using the same procedure one finds::
L[C] = C + merge(DO,FO,DF)
= C + D + merge(O,FO,F)
= C + D + F + merge(O,O)
= C D F O | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c935458b-aa19-47c5-9234-e7822fa26a81 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,057 | supabase-export-v2 | fe3c4048f42e4a3b | L[D] = D A B C
Guido points out in his essay [#]_ that the classic MRO is not so bad in
practice, since one can typically avoids diamonds for classic classes. But all new style classes inherit from ``object``, therefore diamonds are
unavoidable and inconsistencies shows up in every multiple inheritance
graph. | trusted_official_docs | CPython Docs | L[D] = D A B C
Guido points out in his essay [#]_ that the classic MRO is not so bad in
practice, since one can typically avoids diamonds for classic classes. But all new style classes inherit from ``object``, therefore diamonds are
unavoidable and inconsistencies shows up in every multiple inheritance
graph. | L[D] = D A B C
Guido points out in his essay [#]_ that the classic MRO is not so bad in
practice, since one can typically avoids diamonds for classic classes. But all new style classes inherit from ``object``, therefore diamonds are
unavoidable and inconsistencies shows up in every multiple inheritance
graph. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c938876d-8df3-4e8a-878d-06aaddb0513d | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,046 | supabase-export-v2 | 232ea27fc031c51e | Python 2.2 (both for classic classes and new style classes) in this situation, would not raise any exception.
Finally, I would like to point out two lessons we have learned from this
example: | trusted_official_docs | CPython Docs | Python 2.2 (both for classic classes and new style classes) in this situation, would not raise any exception.
Finally, I would like to point out two lessons we have learned from this
example: | Python 2.2 (both for classic classes and new style classes) in this situation, would not raise any exception.
Finally, I would like to point out two lessons we have learned from this
example: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cf7a57e7-d8b9-4a0e-b63b-4ff62546fc34 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,034 | supabase-export-v2 | 63e492a3b4d1c653 | the breaking of local precedence ordering is quite non-intuitive and error prone. This is particularly true since it is a different from old style classes:
>>> class F: remember2buy='spam'
>>> class E(F): remember2buy='eggs'
>>> class G(F,E): pass # doctest: +SKIP
>>> G.remember2buy # doctest: +SKIP
'spam' | trusted_official_docs | CPython Docs | the breaking of local precedence ordering is quite non-intuitive and error prone. This is particularly true since it is a different from old style classes:
>>> class F: remember2buy='spam'
>>> class E(F): remember2buy='eggs'
>>> class G(F,E): pass # doctest: +SKIP
>>> G.remember2buy # doctest: +SKIP
'spam' | the breaking of local precedence ordering is quite non-intuitive and error prone. This is particularly true since it is a different from old style classes:
>>> class F: remember2buy='spam'
>>> class E(F): remember2buy='eggs'
>>> class G(F,E): pass # doctest: +SKIP
>>> G.remember2buy # doctest: +SKIP
'spam' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d26c18fa-3933-44f5-9cea-13779ce1892f | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 57,993 | supabase-export-v2 | dc802902fcaec8d2 | First example. Consider the following hierarchy:
>>> O = object
>>> class F(O): pass
>>> class E(O): pass
>>> class D(O): pass
>>> class C(D,F): pass
>>> class B(D,E): pass
>>> class A(B,C): pass | trusted_official_docs | CPython Docs | First example. Consider the following hierarchy:
>>> O = object
>>> class F(O): pass
>>> class E(O): pass
>>> class D(O): pass
>>> class C(D,F): pass
>>> class B(D,E): pass
>>> class A(B,C): pass | First example. Consider the following hierarchy:
>>> O = object
>>> class F(O): pass
>>> class E(O): pass
>>> class D(O): pass
>>> class C(D,F): pass
>>> class B(D,E): pass
>>> class A(B,C): pass | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d5182ae8-bc27-421f-a0c2-7328777b6bd6 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,024 | supabase-export-v2 | e9a906f2ff3b0d15 | In this section, I will show that both the MRO for classic classes and the MRO for new style classes in Python 2.2 are bad.
It is easier to start with the local precedence ordering. Consider the
following example: | trusted_official_docs | CPython Docs | In this section, I will show that both the MRO for classic classes and the MRO for new style classes in Python 2.2 are bad.
It is easier to start with the local precedence ordering. Consider the
following example: | In this section, I will show that both the MRO for classic classes and the MRO for new style classes in Python 2.2 are bad.
It is easier to start with the local precedence ordering. Consider the
following example: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d936eb07-0bdc-4da9-8051-b5beca299f0e | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,008 | supabase-export-v2 | 178d109d59acbc57 | level, in the sense that lower levels (i.e. more specialized classes) have higher precedence (see the inheritance graph). However, this is not the general case.
I leave as an exercise for the reader to compute the linearization for
my second example: | trusted_official_docs | CPython Docs | level, in the sense that lower levels (i.e. more specialized classes) have higher precedence (see the inheritance graph). However, this is not the general case.
I leave as an exercise for the reader to compute the linearization for
my second example: | level, in the sense that lower levels (i.e. more specialized classes) have higher precedence (see the inheritance graph). However, this is not the general case.
I leave as an exercise for the reader to compute the linearization for
my second example: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
db71c4c3-e4d3-489f-894a-6b9d24ccc08d | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 57,987 | supabase-export-v2 | eb6a88bddbbdfc0b | heads. In this case, it is impossible to construct the merge, Python 2.3 will refuse to create the class C and will raise an exception.*
This prescription ensures that the merge operation *preserves* the
ordering, if the ordering can be preserved. On the other hand, if the
order cannot be preserved (as in the example o... | trusted_official_docs | CPython Docs | heads. In this case, it is impossible to construct the merge, Python 2.3 will refuse to create the class C and will raise an exception.*
This prescription ensures that the merge operation *preserves* the
ordering, if the ordering can be preserved. On the other hand, if the
order cannot be preserved (as in the example o... | heads. In this case, it is impossible to construct the merge, Python 2.3 will refuse to create the class C and will raise an exception.*
This prescription ensures that the merge operation *preserves* the
ordering, if the ordering can be preserved. On the other hand, if the
order cannot be preserved (as in the example o... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ebe12cea-ebe4-4a1a-a418-df925a90fd99 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 57,958 | supabase-export-v2 | a5ade543dd3a9e98 | the linearization. In the Python literature, the idiom "the MRO of C" is also used as a synonymous for the linearization of the class C.
4) For instance, in the case of single inheritance hierarchy, if C is a
subclass of C1, and C1 is a subclass of C2, then the linearization of
C is simply the list [C, C1 , C2]. Howe... | trusted_official_docs | CPython Docs | the linearization. In the Python literature, the idiom "the MRO of C" is also used as a synonymous for the linearization of the class C.
4) For instance, in the case of single inheritance hierarchy, if C is a
subclass of C1, and C1 is a subclass of C2, then the linearization of
C is simply the list [C, C1 , C2]. Howe... | the linearization. In the Python literature, the idiom "the MRO of C" is also used as a synonymous for the linearization of the class C.
4) For instance, in the case of single inheritance hierarchy, if C is a
subclass of C1, and C1 is a subclass of C2, then the linearization of
C is simply the list [C, C1 , C2]. Howe... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f04c73d8-7398-4618-aaf1-78957a256c5d | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,020 | supabase-export-v2 | e08c03a462552b06 | However, it is impossible to compute the linearization for a class C that inherits from A and B::
L[C] = C + merge(AXYO, BYXO, AB)
= C + A + merge(XYO, BYXO, B)
= C + A + B + merge(XYO, YXO) | trusted_official_docs | CPython Docs | However, it is impossible to compute the linearization for a class C that inherits from A and B::
L[C] = C + merge(AXYO, BYXO, AB)
= C + A + merge(XYO, BYXO, B)
= C + A + B + merge(XYO, YXO) | However, it is impossible to compute the linearization for a class C that inherits from A and B::
L[C] = C + merge(AXYO, BYXO, AB)
= C + A + merge(XYO, BYXO, B)
= C + A + B + merge(XYO, YXO) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f170d65e-2ba2-4196-9443-9c729ffd464b | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,012 | supabase-export-v2 | 926b6626a0092852 | .. code-block:: text
6
---
Level 3 | O |
/ --- \
/ | \
/ | \
/ | \
--- --- ---
Level 2 2 | E | 4 | D | | F | 5
--- --- ---
\ / \ /
\ / \ /
\ / \ /
--- ---
Level 1 1 | B | | C | 3
--- ---
\ /
\ /
---
Level 0 0 | A |
--- | trusted_official_docs | CPython Docs | .. code-block:: text
6
---
Level 3 | O |
/ --- \
/ | \
/ | \
/ | \
--- --- ---
Level 2 2 | E | 4 | D | | F | 5
--- --- ---
\ / \ /
\ / \ /
\ / \ /
--- ---
Level 1 1 | B | | C | 3
--- ---
\ /
\ /
---
Level 0 0 | A |
--- | .. code-block:: text
6
---
Level 3 | O |
/ --- \
/ | \
/ | \
/ | \
--- --- ---
Level 2 2 | E | 4 | D | | F | 5
--- --- ---
\ / \ /
\ / \ /
\ / \ /
--- ---
Level 1 1 | B | | C | 3
--- ---
\ /
\ /
---
Level 0 0 | A |
--- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f4622192-60d1-46a3-acf2-d0c1e6f45196 | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 57,996 | supabase-export-v2 | c890271c658bbbee | .. code-block:: text
6
---
Level 3 | O | (more general)
/ --- \
/ | \ |
/ | \ |
/ | \ |
--- --- --- |
Level 2 3 | D | 4| E | | F | 5 |
--- --- --- |
\ \ _ / | |
\ / \ _ | |
\ / \ | |
--- --- |
Level 1 1 | B | | C | 2 |
--- --- |
\ / |
\ / \ /
---
Level 0 0 | A | (more specialized)
--- | trusted_official_docs | CPython Docs | .. code-block:: text
6
---
Level 3 | O | (more general)
/ --- \
/ | \ |
/ | \ |
/ | \ |
--- --- --- |
Level 2 3 | D | 4| E | | F | 5 |
--- --- --- |
\ \ _ / | |
\ / \ _ | |
\ / \ | |
--- --- |
Level 1 1 | B | | C | 2 |
--- --- |
\ / |
\ / \ /
---
Level 0 0 | A | (more specialized)
--- | .. code-block:: text
6
---
Level 3 | O | (more general)
/ --- \
/ | \ |
/ | \ |
/ | \ |
--- --- --- |
Level 2 3 | D | 4| E | | F | 5 |
--- --- --- |
\ \ _ / | |
\ / \ _ | |
\ / \ | |
--- --- |
Level 1 1 | B | | C | 2 |
--- --- |
\ / |
\ / \ /
---
Level 0 0 | A | (more specialized)
--- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f7dfdbbf-a40c-43d8-b94a-9d95bc89eeef | CPython Docs | file://datasets/cpython/Doc/howto/mro.rst | unknown | 020978da-c280-437e-9370-184d98469913 | 58,031 | supabase-export-v2 | 4eb8d4afc3200fa0 | >>> G.remember2buy # doctest: +SKIP 'eggs'
This is a breaking of local precedence ordering since the order in the
local precedence list, i.e. the list of the parents of G, is not
preserved in the Python 2.2 linearization of G:: | trusted_official_docs | CPython Docs | >>> G.remember2buy # doctest: +SKIP 'eggs'
This is a breaking of local precedence ordering since the order in the
local precedence list, i.e. the list of the parents of G, is not
preserved in the Python 2.2 linearization of G:: | >>> G.remember2buy # doctest: +SKIP 'eggs'
This is a breaking of local precedence ordering since the order in the
local precedence list, i.e. the list of the parents of G, is not
preserved in the Python 2.2 linearization of G:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ca1cead9-ed41-4a59-8fb1-3efe08189abc | CPython Docs | file://datasets/cpython/Doc/howto/pyporting.rst | unknown | 7b0de906-7cf4-455a-955d-0302cccf34d9 | 58,083 | supabase-export-v2 | 77b4d3ffb3caa72a | :author: Brett Cannon
Python 2 reached its official end-of-life at the start of 2020. This means
that no new bug reports, fixes, or changes will be made to Python 2 - it's
no longer supported: see :pep:`373` and
`status of Python versions <https://devguide.python.org/versions>`_. | trusted_official_docs | CPython Docs | :author: Brett Cannon
Python 2 reached its official end-of-life at the start of 2020. This means
that no new bug reports, fixes, or changes will be made to Python 2 - it's
no longer supported: see :pep:`373` and
`status of Python versions <https://devguide.python.org/versions>`_. | :author: Brett Cannon
Python 2 reached its official end-of-life at the start of 2020. This means
that no new bug reports, fixes, or changes will be made to Python 2 - it's
no longer supported: see :pep:`373` and
`status of Python versions <https://devguide.python.org/versions>`_. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d0b90564-564c-4b22-9672-b11526a156d9 | CPython Docs | file://datasets/cpython/Doc/howto/pyporting.rst | unknown | 7b0de906-7cf4-455a-955d-0302cccf34d9 | 58,089 | supabase-export-v2 | 81ad4fe4b4c96637 | There are also multiple third-party guides that might be useful:
- `Guide by Fedora <https://portingguide.readthedocs.io>`_
- `PyCon 2020 tutorial <https://www.youtube.com/watch?v=JgIgEjASOlk>`_
- `Guide by DigitalOcean <https://www.digitalocean.com/community/tutorials/how-to-port-python-2-code-to-python-3>`_
- `Guide ... | trusted_official_docs | CPython Docs | There are also multiple third-party guides that might be useful:
- `Guide by Fedora <https://portingguide.readthedocs.io>`_
- `PyCon 2020 tutorial <https://www.youtube.com/watch?v=JgIgEjASOlk>`_
- `Guide by DigitalOcean <https://www.digitalocean.com/community/tutorials/how-to-port-python-2-code-to-python-3>`_
- `Guide ... | There are also multiple third-party guides that might be useful:
- `Guide by Fedora <https://portingguide.readthedocs.io>`_
- `PyCon 2020 tutorial <https://www.youtube.com/watch?v=JgIgEjASOlk>`_
- `Guide by DigitalOcean <https://www.digitalocean.com/community/tutorials/how-to-port-python-2-code-to-python-3>`_
- `Guide ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fee72338-621e-43bf-a752-b68e52c63427 | CPython Docs | file://datasets/cpython/Doc/howto/pyporting.rst | unknown | 7b0de906-7cf4-455a-955d-0302cccf34d9 | 58,084 | supabase-export-v2 | 9d574250374ad2ad | new bug reports, fixes, or changes will be made to Python 2 - it's no longer supported: see :pep:`373` and `status of Python versions <https://devguide.python.org/versions>`_.
If you are looking to port an extension module instead of pure Python code,
please see :ref:`cporting-howto`. | trusted_official_docs | CPython Docs | new bug reports, fixes, or changes will be made to Python 2 - it's no longer supported: see :pep:`373` and `status of Python versions <https://devguide.python.org/versions>`_.
If you are looking to port an extension module instead of pure Python code,
please see :ref:`cporting-howto`. | new bug reports, fixes, or changes will be made to Python 2 - it's no longer supported: see :pep:`373` and `status of Python versions <https://devguide.python.org/versions>`_.
If you are looking to port an extension module instead of pure Python code,
please see :ref:`cporting-howto`. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
01dd16d1-219d-48c4-b3a2-48a6482b2d8b | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,288 | supabase-export-v2 | 1bd3a36c3acc05fe | Conclusion ==========
The :mod:`argparse` module offers a lot more than shown here. Its docs are quite detailed and thorough, and full of examples. Having gone through this tutorial, you should easily digest them
without feeling overwhelmed. | trusted_official_docs | CPython Docs | Conclusion ==========
The :mod:`argparse` module offers a lot more than shown here. Its docs are quite detailed and thorough, and full of examples. Having gone through this tutorial, you should easily digest them
without feeling overwhelmed. | Conclusion ==========
The :mod:`argparse` module offers a lot more than shown here. Its docs are quite detailed and thorough, and full of examples. Having gone through this tutorial, you should easily digest them
without feeling overwhelmed. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0369b5d7-f07e-47f1-b21f-29ccf87de330 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,156 | supabase-export-v2 | 2d58535b1e3fe6b2 | relevant variable, in this case ``args.verbosity``, is given ``None`` as a value, which is the reason it fails the truth test of the :keyword:`if` statement.
* The help message is a bit different. | trusted_official_docs | CPython Docs | relevant variable, in this case ``args.verbosity``, is given ``None`` as a value, which is the reason it fails the truth test of the :keyword:`if` statement.
* The help message is a bit different. | relevant variable, in this case ``args.verbosity``, is given ``None`` as a value, which is the reason it fails the truth test of the :keyword:`if` statement.
* The help message is a bit different. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0483ad5b-0026-4764-a4ab-e736efbb84c7 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,113 | supabase-export-v2 | 64cce88da56589e9 | exit $ python prog.py --verbose usage: prog.py [-h] prog.py: error: unrecognized arguments: --verbose $ python prog.py foo usage: prog.py [-h] prog.py: error: unrecognized arguments: foo
Here is what is happening: | trusted_official_docs | CPython Docs | exit $ python prog.py --verbose usage: prog.py [-h] prog.py: error: unrecognized arguments: --verbose $ python prog.py foo usage: prog.py [-h] prog.py: error: unrecognized arguments: foo
Here is what is happening: | exit $ python prog.py --verbose usage: prog.py [-h] prog.py: error: unrecognized arguments: --verbose $ python prog.py foo usage: prog.py [-h] prog.py: error: unrecognized arguments: foo
Here is what is happening: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
05fdcebc-8918-4bd8-9a51-956c2294407a | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,275 | supabase-export-v2 | 0a2067a2e93c7201 | Custom type converters ======================
The :mod:`argparse` module allows you to specify custom type converters for
your command-line arguments. This allows you to modify user input before it's
stored in the :class:`argparse.Namespace`. This can be useful when you need to
pre-process the input before it is used i... | trusted_official_docs | CPython Docs | Custom type converters ======================
The :mod:`argparse` module allows you to specify custom type converters for
your command-line arguments. This allows you to modify user input before it's
stored in the :class:`argparse.Namespace`. This can be useful when you need to
pre-process the input before it is used i... | Custom type converters ======================
The :mod:`argparse` module allows you to specify custom type converters for
your command-line arguments. This allows you to modify user input before it's
stored in the :class:`argparse.Namespace`. This can be useful when you need to
pre-process the input before it is used i... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0ead76bb-4d85-4c38-883f-642bb11258a0 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,199 | supabase-export-v2 | 3cc7f79a631949bd | options: -h, --help show this help message and exit -v, --verbosity increase output verbosity $ python prog.py 4 -vvv 16
* Yes, it's now more of a flag (similar to ``action="store_true"``) in the
previous version of our script. That should explain the complaint. | trusted_official_docs | CPython Docs | options: -h, --help show this help message and exit -v, --verbosity increase output verbosity $ python prog.py 4 -vvv 16
* Yes, it's now more of a flag (similar to ``action="store_true"``) in the
previous version of our script. That should explain the complaint. | options: -h, --help show this help message and exit -v, --verbosity increase output verbosity $ python prog.py 4 -vvv 16
* Yes, it's now more of a flag (similar to ``action="store_true"``) in the
previous version of our script. That should explain the complaint. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0edbfbc4-a5dc-45c4-af0b-c1b5c99e3ff6 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,185 | supabase-export-v2 | 73691b6da1a986af | 4 -v 1 4^2 == 16 $ python prog.py 4 -v 2 the square of 4 equals 16 $ python prog.py 4 -v 3 16
These all look good except the last one, which exposes a bug in our program. Let's fix it by restricting the values the ``--verbosity`` option can accept:: | trusted_official_docs | CPython Docs | 4 -v 1 4^2 == 16 $ python prog.py 4 -v 2 the square of 4 equals 16 $ python prog.py 4 -v 3 16
These all look good except the last one, which exposes a bug in our program. Let's fix it by restricting the values the ``--verbosity`` option can accept:: | 4 -v 1 4^2 == 16 $ python prog.py 4 -v 2 the square of 4 equals 16 $ python prog.py 4 -v 3 16
These all look good except the last one, which exposes a bug in our program. Let's fix it by restricting the values the ``--verbosity`` option can accept:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1100b871-304a-4d90-8114-d865b2d89177 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,194 | supabase-export-v2 | a0e115e3b6960f2f | args = parser.parse_args() answer = args.square**2 if args.verbosity == 2: print(f"the square of {args.square} equals {answer}") elif args.verbosity == 1: print(f"{args.square}^2 == {answer}") else: print(answer)
We have introduced another action, "count",
to count the number of occurrences of specific options. | trusted_official_docs | CPython Docs | args = parser.parse_args() answer = args.square**2 if args.verbosity == 2: print(f"the square of {args.square} equals {answer}") elif args.verbosity == 1: print(f"{args.square}^2 == {answer}") else: print(answer)
We have introduced another action, "count",
to count the number of occurrences of specific options. | args = parser.parse_args() answer = args.square**2 if args.verbosity == 2: print(f"the square of {args.square} equals {answer}") elif args.verbosity == 1: print(f"{args.square}^2 == {answer}") else: print(answer)
We have introduced another action, "count",
to count the number of occurrences of specific options. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
153d49bd-f612-489e-a6f3-43886a4b84a9 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,270 | supabase-export-v2 | 5089ab8c6c2b905b | all translatable strings from the :mod:`argparse` module and output them into a file named ``messages.po``. This command assumes that your Python installation is in ``/usr/lib``.
You can find out the location of the :mod:`argparse` module on your system
using this script:: | trusted_official_docs | CPython Docs | all translatable strings from the :mod:`argparse` module and output them into a file named ``messages.po``. This command assumes that your Python installation is in ``/usr/lib``.
You can find out the location of the :mod:`argparse` module on your system
using this script:: | all translatable strings from the :mod:`argparse` module and output them into a file named ``messages.po``. This command assumes that your Python installation is in ``/usr/lib``.
You can find out the location of the :mod:`argparse` module on your system
using this script:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1a4e2f28-8dac-4226-87a9-befeeb327a65 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,164 | supabase-export-v2 | da2f234a949f49ba | Here is what is happening:
* The option is now more of a flag than something that requires a value. We even changed the name of the option to match that idea. Note that we now specify a new keyword, ``action``, and give it the value
``"store_true"``. This means that, if the option is specified,
assign the value ``Tru... | trusted_official_docs | CPython Docs | Here is what is happening:
* The option is now more of a flag than something that requires a value. We even changed the name of the option to match that idea. Note that we now specify a new keyword, ``action``, and give it the value
``"store_true"``. This means that, if the option is specified,
assign the value ``Tru... | Here is what is happening:
* The option is now more of a flag than something that requires a value. We even changed the name of the option to match that idea. Note that we now specify a new keyword, ``action``, and give it the value
``"store_true"``. This means that, if the option is specified,
assign the value ``Tru... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1c2dc064-365c-4c49-bc62-b005bcce7d86 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,152 | supabase-export-v2 | 23d9f70189a8e49a | $ python prog.py --verbosity 1 verbosity turned on $ python prog.py $ python prog.py --help usage: prog.py [-h] [--verbosity VERBOSITY]
options:
-h, --help show this help message and exit
--verbosity VERBOSITY
increase output verbosity
$ python prog.py --verbosity
usage: prog.py [-h] [--verbosity VERBOSITY]
prog.... | trusted_official_docs | CPython Docs | $ python prog.py --verbosity 1 verbosity turned on $ python prog.py $ python prog.py --help usage: prog.py [-h] [--verbosity VERBOSITY]
options:
-h, --help show this help message and exit
--verbosity VERBOSITY
increase output verbosity
$ python prog.py --verbosity
usage: prog.py [-h] [--verbosity VERBOSITY]
prog.... | $ python prog.py --verbosity 1 verbosity turned on $ python prog.py $ python prog.py --help usage: prog.py [-h] [--verbosity VERBOSITY]
options:
-h, --help show this help message and exit
--verbosity VERBOSITY
increase output verbosity
$ python prog.py --verbosity
usage: prog.py [-h] [--verbosity VERBOSITY]
prog.... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1e45dbcb-ade2-4d3d-9368-d858d437bf5f | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,215 | supabase-export-v2 | 4197c06de05ebe71 | args = parser.parse_args() answer = args.square**2 if args.verbosity >= 2: print(f"the square of {args.square} equals {answer}") elif args.verbosity >= 1: print(f"{args.square}^2 == {answer}") else: print(answer)
We've just introduced yet another keyword, ``default``. We've set it to ``0`` in order to make it comparabl... | trusted_official_docs | CPython Docs | args = parser.parse_args() answer = args.square**2 if args.verbosity >= 2: print(f"the square of {args.square} equals {answer}") elif args.verbosity >= 1: print(f"{args.square}^2 == {answer}") else: print(answer)
We've just introduced yet another keyword, ``default``. We've set it to ``0`` in order to make it comparabl... | args = parser.parse_args() answer = args.square**2 if args.verbosity >= 2: print(f"the square of {args.square} equals {answer}") elif args.verbosity >= 1: print(f"{args.square}^2 == {answer}") else: print(answer)
We've just introduced yet another keyword, ``default``. We've set it to ``0`` in order to make it comparabl... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
21d6d770-3a90-4ff5-9aa4-95b28cd277cf | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,096 | supabase-export-v2 | c69886b15ebb7fef | .. note::
The standard library includes two other libraries directly related
to command-line parameter processing: the lower level :mod:`optparse`
module (which may require more code to configure for a given application,
but also allows an application to request behaviors that ``argparse``
doesn't support), and the... | trusted_official_docs | CPython Docs | .. note::
The standard library includes two other libraries directly related
to command-line parameter processing: the lower level :mod:`optparse`
module (which may require more code to configure for a given application,
but also allows an application to request behaviors that ``argparse``
doesn't support), and the... | .. note::
The standard library includes two other libraries directly related
to command-line parameter processing: the lower level :mod:`optparse`
module (which may require more code to configure for a given application,
but also allows an application to request behaviors that ``argparse``
doesn't support), and the... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
24de7e93-614c-4188-9db0-1ac8e8c926c8 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,212 | supabase-export-v2 | 9b50875b65fb922c | Traceback (most recent call last): File "prog.py", line 11, in <module> if args.verbosity >= 2: TypeError: '>=' not supported between instances of 'NoneType' and 'int'
* First output went well, and fixes the bug we had before. That is, we want any value >= 2 to be as verbose as possible. | trusted_official_docs | CPython Docs | Traceback (most recent call last): File "prog.py", line 11, in <module> if args.verbosity >= 2: TypeError: '>=' not supported between instances of 'NoneType' and 'int'
* First output went well, and fixes the bug we had before. That is, we want any value >= 2 to be as verbose as possible. | Traceback (most recent call last): File "prog.py", line 11, in <module> if args.verbosity >= 2: TypeError: '>=' not supported between instances of 'NoneType' and 'int'
* First output went well, and fixes the bug we had before. That is, we want any value >= 2 to be as verbose as possible. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
29a816a5-7ae4-4acf-9b1c-63e56ce4edb6 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,142 | supabase-export-v2 | b2ac0ac8caf0d1df | :mod:`argparse` treats the options we give it as strings, unless we tell it otherwise. So, let's tell :mod:`argparse` to treat that input as an integer::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", help="display a square of a given number",
type=int)
args = parser.parse_args()
... | trusted_official_docs | CPython Docs | :mod:`argparse` treats the options we give it as strings, unless we tell it otherwise. So, let's tell :mod:`argparse` to treat that input as an integer::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", help="display a square of a given number",
type=int)
args = parser.parse_args()
... | :mod:`argparse` treats the options we give it as strings, unless we tell it otherwise. So, let's tell :mod:`argparse` to treat that input as an integer::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", help="display a square of a given number",
type=int)
args = parser.parse_args()
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2b2ddfa6-b6e3-43b1-9e12-9d2b9d034b28 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,188 | supabase-export-v2 | 1fcd379b5fe8fd81 | .. code-block:: shell-session
$ python prog.py 4 -v 3
usage: prog.py [-h] [-v {0,1,2}] square
prog.py: error: argument -v/--verbosity: invalid choice: 3 (choose from 0, 1, 2)
$ python prog.py 4 -h
usage: prog.py [-h] [-v {0,1,2}] square | trusted_official_docs | CPython Docs | .. code-block:: shell-session
$ python prog.py 4 -v 3
usage: prog.py [-h] [-v {0,1,2}] square
prog.py: error: argument -v/--verbosity: invalid choice: 3 (choose from 0, 1, 2)
$ python prog.py 4 -h
usage: prog.py [-h] [-v {0,1,2}] square | .. code-block:: shell-session
$ python prog.py 4 -v 3
usage: prog.py [-h] [-v {0,1,2}] square
prog.py: error: argument -v/--verbosity: invalid choice: 3 (choose from 0, 1, 2)
$ python prog.py 4 -h
usage: prog.py [-h] [-v {0,1,2}] square | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2ed2d3d7-8ed4-4d19-875f-2f34376c18a6 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,192 | supabase-export-v2 | c7726cf0c888a310 | Note that the change also reflects both in the error message as well as the help string.
Now, let's use a different approach of playing with verbosity, which is pretty
common. It also matches the way the CPython executable handles its own
verbosity argument (check the output of ``python --help``):: | trusted_official_docs | CPython Docs | Note that the change also reflects both in the error message as well as the help string.
Now, let's use a different approach of playing with verbosity, which is pretty
common. It also matches the way the CPython executable handles its own
verbosity argument (check the output of ``python --help``):: | Note that the change also reflects both in the error message as well as the help string.
Now, let's use a different approach of playing with verbosity, which is pretty
common. It also matches the way the CPython executable handles its own
verbosity argument (check the output of ``python --help``):: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
312e1eb1-9c00-4f7b-bd80-d2c72e0f187c | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,223 | supabase-export-v2 | 19e94e1b3e8c4586 | .. code-block:: shell-session
$ python prog.py
usage: prog.py [-h] [-v] x y
prog.py: error: the following arguments are required: x, y
$ python prog.py -h
usage: prog.py [-h] [-v] x y | trusted_official_docs | CPython Docs | .. code-block:: shell-session
$ python prog.py
usage: prog.py [-h] [-v] x y
prog.py: error: the following arguments are required: x, y
$ python prog.py -h
usage: prog.py [-h] [-v] x y | .. code-block:: shell-session
$ python prog.py
usage: prog.py [-h] [-v] x y
prog.py: error: the following arguments are required: x, y
$ python prog.py -h
usage: prog.py [-h] [-v] x y | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
32eb9374-c2da-4b19-a58b-baa51332846e | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,101 | supabase-export-v2 | f713df4b14837071 | ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified. ...
A few concepts we can learn from the four commands: | trusted_official_docs | CPython Docs | ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified. ...
A few concepts we can learn from the four commands: | ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified. ...
A few concepts we can learn from the four commands: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
33ba24f4-be6b-4d61-b881-19819ea0c607 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,105 | supabase-export-v2 | e4a11b40385328d1 | we display more info for each file instead of just showing the file names. The ``-l`` in that case is known as an optional argument.
* That's a snippet of the help text. It's very useful in that you can
come across a program you have never used before, and can figure out
how it works simply by reading its help text. | trusted_official_docs | CPython Docs | we display more info for each file instead of just showing the file names. The ``-l`` in that case is known as an optional argument.
* That's a snippet of the help text. It's very useful in that you can
come across a program you have never used before, and can figure out
how it works simply by reading its help text. | we display more info for each file instead of just showing the file names. The ``-l`` in that case is known as an optional argument.
* That's a snippet of the help text. It's very useful in that you can
come across a program you have never used before, and can figure out
how it works simply by reading its help text. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
37d5cd74-2c2f-4d96-b53e-38f1429e2496 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,233 | supabase-export-v2 | 9bb507a39c29dc67 | deciding whether an argument is positional or for an argument, ``--`` can be used to tell :meth:`~ArgumentParser.parse_args` that everything after that is a positional argument::
>>> parser = argparse.ArgumentParser(prog='PROG')
>>> parser.add_argument('-n', nargs='+')
>>> parser.add_argument('args', nargs='*') | trusted_official_docs | CPython Docs | deciding whether an argument is positional or for an argument, ``--`` can be used to tell :meth:`~ArgumentParser.parse_args` that everything after that is a positional argument::
>>> parser = argparse.ArgumentParser(prog='PROG')
>>> parser.add_argument('-n', nargs='+')
>>> parser.add_argument('args', nargs='*') | deciding whether an argument is positional or for an argument, ``--`` can be used to tell :meth:`~ArgumentParser.parse_args` that everything after that is a positional argument::
>>> parser = argparse.ArgumentParser(prog='PROG')
>>> parser.add_argument('-n', nargs='+')
>>> parser.add_argument('args', nargs='*') | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
381fe335-05b9-4885-ac46-6bcc5a27965b | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,245 | supabase-export-v2 | ae4053791a7e9d2d | .. code-block:: shell-session
$ python prog.py 4 2
4^2 == 16
$ python prog.py 4 2 -q
16
$ python prog.py 4 2 -v
4 to the power 2 equals 16
$ python prog.py 4 2 -vq
usage: prog.py [-h] [-v | -q] x y
prog.py: error: argument -q/--quiet: not allowed with argument -v/--verbose
$ python prog.py 4 2 -v --quiet
usag... | trusted_official_docs | CPython Docs | .. code-block:: shell-session
$ python prog.py 4 2
4^2 == 16
$ python prog.py 4 2 -q
16
$ python prog.py 4 2 -v
4 to the power 2 equals 16
$ python prog.py 4 2 -vq
usage: prog.py [-h] [-v | -q] x y
prog.py: error: argument -q/--quiet: not allowed with argument -v/--verbose
$ python prog.py 4 2 -v --quiet
usag... | .. code-block:: shell-session
$ python prog.py 4 2
4^2 == 16
$ python prog.py 4 2 -q
16
$ python prog.py 4 2 -v
4 to the power 2 equals 16
$ python prog.py 4 2 -vq
usage: prog.py [-h] [-v | -q] x y
prog.py: error: argument -q/--quiet: not allowed with argument -v/--verbose
$ python prog.py 4 2 -v --quiet
usag... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3d2468b4-84ed-4200-8512-8ae06c8bfe0e | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,224 | supabase-export-v2 | 2f8914ac7b46334a | usage: prog.py [-h] [-v] x y prog.py: error: the following arguments are required: x, y $ python prog.py -h usage: prog.py [-h] [-v] x y
positional arguments:
x the base
y the exponent | trusted_official_docs | CPython Docs | usage: prog.py [-h] [-v] x y prog.py: error: the following arguments are required: x, y $ python prog.py -h usage: prog.py [-h] [-v] x y
positional arguments:
x the base
y the exponent | usage: prog.py [-h] [-v] x y prog.py: error: the following arguments are required: x, y $ python prog.py -h usage: prog.py [-h] [-v] x y
positional arguments:
x the base
y the exponent | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3f645400-b10c-415d-8bb2-86346acf0f24 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,243 | supabase-export-v2 | dfbcfca4c899a0ee | if args.quiet: print(answer) elif args.verbose: print(f"{args.x} to the power {args.y} equals {answer}") else: print(f"{args.x}^{args.y} == {answer}")
Our program is now simpler, and we've lost some functionality for the sake of
demonstration. Anyways, here's the output: | trusted_official_docs | CPython Docs | if args.quiet: print(answer) elif args.verbose: print(f"{args.x} to the power {args.y} equals {answer}") else: print(f"{args.x}^{args.y} == {answer}")
Our program is now simpler, and we've lost some functionality for the sake of
demonstration. Anyways, here's the output: | if args.quiet: print(answer) elif args.verbose: print(f"{args.x} to the power {args.y} equals {answer}") else: print(f"{args.x}^{args.y} == {answer}")
Our program is now simpler, and we've lost some functionality for the sake of
demonstration. Anyways, here's the output: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4634a083-ac3c-4c9f-a94e-eee5fe7547e5 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,191 | supabase-export-v2 | de6ba521deeb7aba | options: -h, --help show this help message and exit -v, --verbosity {0,1,2} increase output verbosity
Note that the change also reflects both in the error message as well as the
help string. | trusted_official_docs | CPython Docs | options: -h, --help show this help message and exit -v, --verbosity {0,1,2} increase output verbosity
Note that the change also reflects both in the error message as well as the
help string. | options: -h, --help show this help message and exit -v, --verbosity {0,1,2} increase output verbosity
Note that the change also reflects both in the error message as well as the
help string. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
47f9e2ff-6fa7-4a12-86d5-681d4ac8b931 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,198 | supabase-export-v2 | 430a4b6c2575c4ed | positional arguments: square display a square of a given number
options:
-h, --help show this help message and exit
-v, --verbosity increase output verbosity
$ python prog.py 4 -vvv
16 | trusted_official_docs | CPython Docs | positional arguments: square display a square of a given number
options:
-h, --help show this help message and exit
-v, --verbosity increase output verbosity
$ python prog.py 4 -vvv
16 | positional arguments: square display a square of a given number
options:
-h, --help show this help message and exit
-v, --verbosity increase output verbosity
$ python prog.py 4 -vvv
16 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
49240587-206b-4789-ba92-0dcd22d2696b | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,251 | supabase-export-v2 | a9eb9e6e0ba61b6f | if args.quiet: print(answer) elif args.verbose: print(f"{args.x} to the power {args.y} equals {answer}") else: print(f"{args.x}^{args.y} == {answer}")
Note that slight difference in the usage text. Note the ``[-v | -q]``,
which tells us that we can either use ``-v`` or ``-q``,
but not both at the same time: | trusted_official_docs | CPython Docs | if args.quiet: print(answer) elif args.verbose: print(f"{args.x} to the power {args.y} equals {answer}") else: print(f"{args.x}^{args.y} == {answer}")
Note that slight difference in the usage text. Note the ``[-v | -q]``,
which tells us that we can either use ``-v`` or ``-q``,
but not both at the same time: | if args.quiet: print(answer) elif args.verbose: print(f"{args.x} to the power {args.y} equals {answer}") else: print(f"{args.x}^{args.y} == {answer}")
Note that slight difference in the usage text. Note the ``[-v | -q]``,
which tells us that we can either use ``-v`` or ``-q``,
but not both at the same time: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4cadb38f-0fe9-4d7e-b07c-3fc687a2fa63 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,149 | supabase-export-v2 | dd358d9f45790f78 | So far we have been playing with positional arguments. Let us have a look on how to add optional ones::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--verbosity", help="increase output verbosity")
args = parser.parse_args()
if args.verbosity:
print("verbosity turned on") | trusted_official_docs | CPython Docs | So far we have been playing with positional arguments. Let us have a look on how to add optional ones::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--verbosity", help="increase output verbosity")
args = parser.parse_args()
if args.verbosity:
print("verbosity turned on") | So far we have been playing with positional arguments. Let us have a look on how to add optional ones::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--verbosity", help="increase output verbosity")
args = parser.parse_args()
if args.verbosity:
print("verbosity turned on") | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
518555ad-ee21-4d60-be76-ce8b27da5442 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,285 | supabase-export-v2 | d2ae86f93372e23e | * Created a parser with custom prefix characters using the ``prefix_chars`` parameter.
* Defined two arguments, ``-a`` and ``+a``, which used the ``type`` parameter to
create custom type converters to store the value in a tuple with the prefix. | trusted_official_docs | CPython Docs | * Created a parser with custom prefix characters using the ``prefix_chars`` parameter.
* Defined two arguments, ``-a`` and ``+a``, which used the ``type`` parameter to
create custom type converters to store the value in a tuple with the prefix. | * Created a parser with custom prefix characters using the ``prefix_chars`` parameter.
* Defined two arguments, ``-a`` and ``+a``, which used the ``type`` parameter to
create custom type converters to store the value in a tuple with the prefix. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
53b9e277-79df-4b53-a0d1-0809f3c1fc9e | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,259 | supabase-export-v2 | b78222ae43fb98c6 | text and error messages are all made translatable using the :mod:`gettext` module. This allows applications to easily localize messages produced by :mod:`argparse`. See also :ref:`i18n-howto`.
For instance, in this :mod:`argparse` output: | trusted_official_docs | CPython Docs | text and error messages are all made translatable using the :mod:`gettext` module. This allows applications to easily localize messages produced by :mod:`argparse`. See also :ref:`i18n-howto`.
For instance, in this :mod:`argparse` output: | text and error messages are all made translatable using the :mod:`gettext` module. This allows applications to easily localize messages produced by :mod:`argparse`. See also :ref:`i18n-howto`.
For instance, in this :mod:`argparse` output: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5588a4dc-725f-4a6a-99b7-48864e6dae56 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,200 | supabase-export-v2 | ffd1cc131d5b6529 | * Yes, it's now more of a flag (similar to ``action="store_true"``) in the previous version of our script. That should explain the complaint.
* It also behaves similar to "store_true" action. | trusted_official_docs | CPython Docs | * Yes, it's now more of a flag (similar to ``action="store_true"``) in the previous version of our script. That should explain the complaint.
* It also behaves similar to "store_true" action. | * Yes, it's now more of a flag (similar to ``action="store_true"``) in the previous version of our script. That should explain the complaint.
* It also behaves similar to "store_true" action. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
55aaaaaa-b330-4faa-9b82-a316a3854ffb | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,102 | supabase-export-v2 | fb8a14854edee2e0 | A few concepts we can learn from the four commands:
* The :command:`ls` command is useful when run without any options at all. It defaults
to displaying the contents of the current directory. | trusted_official_docs | CPython Docs | A few concepts we can learn from the four commands:
* The :command:`ls` command is useful when run without any options at all. It defaults
to displaying the contents of the current directory. | A few concepts we can learn from the four commands:
* The :command:`ls` command is useful when run without any options at all. It defaults
to displaying the contents of the current directory. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
58630f36-edc4-4dc5-b64b-5901e70e46ea | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,202 | supabase-export-v2 | 422dbfcf60268ffd | * Now here's a demonstration of what the "count" action gives. You've probably seen this sort of usage before.
* And if you don't specify the ``-v`` flag, that flag is considered to have
``None`` value. | trusted_official_docs | CPython Docs | * Now here's a demonstration of what the "count" action gives. You've probably seen this sort of usage before.
* And if you don't specify the ``-v`` flag, that flag is considered to have
``None`` value. | * Now here's a demonstration of what the "count" action gives. You've probably seen this sort of usage before.
* And if you don't specify the ``-v`` flag, that flag is considered to have
``None`` value. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5bfb554b-4f84-4d8e-9430-95931d242666 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,159 | supabase-export-v2 | f23a42e761306aed | accepts arbitrary integer values for ``--verbosity``, but for our simple program, only two values are actually useful, ``True`` or ``False``. Let's modify the code accordingly::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--verbose", help="increase output verbosity",
action="store_true")
... | trusted_official_docs | CPython Docs | accepts arbitrary integer values for ``--verbosity``, but for our simple program, only two values are actually useful, ``True`` or ``False``. Let's modify the code accordingly::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--verbose", help="increase output verbosity",
action="store_true")
... | accepts arbitrary integer values for ``--verbosity``, but for our simple program, only two values are actually useful, ``True`` or ``False``. Let's modify the code accordingly::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--verbose", help="increase output verbosity",
action="store_true")
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5bff60a4-456b-4d40-9cad-ad882a51cfb7 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,266 | supabase-export-v2 | bbe729261b6bf320 | The strings ``usage:``, ``positional arguments:``, ``options:`` and ``show this help message and exit`` are all translatable.
In order to translate these strings, they must first be extracted
into a ``.po`` file. For example, using `Babel <https://babel.pocoo.org/>`__,
run this command: | trusted_official_docs | CPython Docs | The strings ``usage:``, ``positional arguments:``, ``options:`` and ``show this help message and exit`` are all translatable.
In order to translate these strings, they must first be extracted
into a ``.po`` file. For example, using `Babel <https://babel.pocoo.org/>`__,
run this command: | The strings ``usage:``, ``positional arguments:``, ``options:`` and ``show this help message and exit`` are all translatable.
In order to translate these strings, they must first be extracted
into a ``.po`` file. For example, using `Babel <https://babel.pocoo.org/>`__,
run this command: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5ce810c9-347c-4f29-bf22-49ee8d7b99d2 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,189 | supabase-export-v2 | 31e4f0c50e7e5b9e | {0,1,2}] square prog.py: error: argument -v/--verbosity: invalid choice: 3 (choose from 0, 1, 2) $ python prog.py 4 -h usage: prog.py [-h] [-v {0,1,2}] square
positional arguments:
square display a square of a given number | trusted_official_docs | CPython Docs | {0,1,2}] square prog.py: error: argument -v/--verbosity: invalid choice: 3 (choose from 0, 1, 2) $ python prog.py 4 -h usage: prog.py [-h] [-v {0,1,2}] square
positional arguments:
square display a square of a given number | {0,1,2}] square prog.py: error: argument -v/--verbosity: invalid choice: 3 (choose from 0, 1, 2) $ python prog.py 4 -h usage: prog.py [-h] [-v {0,1,2}] square
positional arguments:
square display a square of a given number | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5ddfc965-f51c-4433-847d-5b94b8c6c88d | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,258 | supabase-export-v2 | c02e7789a1df05db | How to translate the argparse output ====================================
The output of the :mod:`argparse` module such as its help text and error
messages are all made translatable using the :mod:`gettext` module. This
allows applications to easily localize messages produced by
:mod:`argparse`. See also :ref:`i18n-how... | trusted_official_docs | CPython Docs | How to translate the argparse output ====================================
The output of the :mod:`argparse` module such as its help text and error
messages are all made translatable using the :mod:`gettext` module. This
allows applications to easily localize messages produced by
:mod:`argparse`. See also :ref:`i18n-how... | How to translate the argparse output ====================================
The output of the :mod:`argparse` module such as its help text and error
messages are all made translatable using the :mod:`gettext` module. This
allows applications to easily localize messages produced by
:mod:`argparse`. See also :ref:`i18n-how... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5e3a3d55-84c6-4ce4-98ab-0b0667598354 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,141 | supabase-export-v2 | 0d1b43d90ea7f6ac | prog.py 4 Traceback (most recent call last): File "prog.py", line 5, in <module> print(args.square**2) TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
That didn't go so well. That's because :mod:`argparse` treats the options we
give it as strings, unless we tell it otherwise. So, let's tell
:mod... | trusted_official_docs | CPython Docs | prog.py 4 Traceback (most recent call last): File "prog.py", line 5, in <module> print(args.square**2) TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
That didn't go so well. That's because :mod:`argparse` treats the options we
give it as strings, unless we tell it otherwise. So, let's tell
:mod... | prog.py 4 Traceback (most recent call last): File "prog.py", line 5, in <module> print(args.square**2) TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
That didn't go so well. That's because :mod:`argparse` treats the options we
give it as strings, unless we tell it otherwise. So, let's tell
:mod... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5f607c4e-9e42-429f-9959-90c05987d8a5 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,205 | supabase-export-v2 | 5c9bc62e82908b0e | new ability our script has acquired, but that can always be fixed by improving the documentation for our script (e.g. via the ``help`` keyword argument).
* That last output exposes a bug in our program. | trusted_official_docs | CPython Docs | new ability our script has acquired, but that can always be fixed by improving the documentation for our script (e.g. via the ``help`` keyword argument).
* That last output exposes a bug in our program. | new ability our script has acquired, but that can always be fixed by improving the documentation for our script (e.g. via the ``help`` keyword argument).
* That last output exposes a bug in our program. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
60521096-21c8-4992-90f7-e7ac833703f7 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,269 | supabase-export-v2 | cce342e091147d69 | $ pybabel extract -o messages.po /usr/lib/python3.12/argparse.py
This command will extract all translatable strings from the :mod:`argparse`
module and output them into a file named ``messages.po``. This command assumes
that your Python installation is in ``/usr/lib``. | trusted_official_docs | CPython Docs | $ pybabel extract -o messages.po /usr/lib/python3.12/argparse.py
This command will extract all translatable strings from the :mod:`argparse`
module and output them into a file named ``messages.po``. This command assumes
that your Python installation is in ``/usr/lib``. | $ pybabel extract -o messages.po /usr/lib/python3.12/argparse.py
This command will extract all translatable strings from the :mod:`argparse`
module and output them into a file named ``messages.po``. This command assumes
that your Python installation is in ``/usr/lib``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
63034b78-5f8c-4f01-ab66-c6265e5a4d84 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,165 | supabase-export-v2 | 62a8f9036a752ab9 | and give it the value ``"store_true"``. This means that, if the option is specified, assign the value ``True`` to ``args.verbose``. Not specifying it implies ``False``.
* It complains when you specify a value, in true spirit of what flags
actually are. | trusted_official_docs | CPython Docs | and give it the value ``"store_true"``. This means that, if the option is specified, assign the value ``True`` to ``args.verbose``. Not specifying it implies ``False``.
* It complains when you specify a value, in true spirit of what flags
actually are. | and give it the value ``"store_true"``. This means that, if the option is specified, assign the value ``True`` to ``args.verbose``. Not specifying it implies ``False``.
* It complains when you specify a value, in true spirit of what flags
actually are. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
64d5b122-ae22-4382-bc7f-b0429220ecf7 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,286 | supabase-export-v2 | 8b6387eb49e3c63f | two arguments, ``-a`` and ``+a``, which used the ``type`` parameter to create custom type converters to store the value in a tuple with the prefix.
Without the custom type converters, the arguments would have treated the ``-a``
and ``+a`` as the same argument, which would have been undesirable. By using custom
type con... | trusted_official_docs | CPython Docs | two arguments, ``-a`` and ``+a``, which used the ``type`` parameter to create custom type converters to store the value in a tuple with the prefix.
Without the custom type converters, the arguments would have treated the ``-a``
and ``+a`` as the same argument, which would have been undesirable. By using custom
type con... | two arguments, ``-a`` and ``+a``, which used the ``type`` parameter to create custom type converters to store the value in a tuple with the prefix.
Without the custom type converters, the arguments would have treated the ``-a``
and ``+a`` as the same argument, which would have been undesirable. By using custom
type con... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
680badd7-1679-4afb-aed7-5bd0879ce947 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,193 | supabase-export-v2 | 0a06034a8c767a5c | with verbosity, which is pretty common. It also matches the way the CPython executable handles its own verbosity argument (check the output of ``python --help``)::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", type=int,
help="display the square of a given number")
parser.add_argum... | trusted_official_docs | CPython Docs | with verbosity, which is pretty common. It also matches the way the CPython executable handles its own verbosity argument (check the output of ``python --help``)::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", type=int,
help="display the square of a given number")
parser.add_argum... | with verbosity, which is pretty common. It also matches the way the CPython executable handles its own verbosity argument (check the output of ``python --help``)::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", type=int,
help="display the square of a given number")
parser.add_argum... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
68d7fa0a-b11b-4de7-9cb3-7f91c989c249 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,213 | supabase-export-v2 | d98c6d5cdd8b00dd | First output went well, and fixes the bug we had before. That is, we want any value >= 2 to be as verbose as possible.
* Third output not so good. | trusted_official_docs | CPython Docs | First output went well, and fixes the bug we had before. That is, we want any value >= 2 to be as verbose as possible.
* Third output not so good. | First output went well, and fixes the bug we had before. That is, we want any value >= 2 to be as verbose as possible.
* Third output not so good. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6a3df3c5-6bef-407e-a240-aab158953d2c | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,127 | supabase-export-v2 | 88d8f84d6029afed | specify which command-line options the program is willing to accept. In this case, I've named it ``echo`` so that it's in line with its function.
* Calling our program now requires us to specify an option. | trusted_official_docs | CPython Docs | specify which command-line options the program is willing to accept. In this case, I've named it ``echo`` so that it's in line with its function.
* Calling our program now requires us to specify an option. | specify which command-line options the program is willing to accept. In this case, I've named it ``echo`` so that it's in line with its function.
* Calling our program now requires us to specify an option. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6d16c2d4-b5a3-48af-8786-23e97dbeb9b8 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,204 | supabase-export-v2 | a24d39e5170f40a2 | * As should be expected, specifying the long form of the flag, we should get the same output.
* Sadly, our help output isn't very informative on the new ability our script
has acquired, but that can always be fixed by improving the documentation for
our script (e.g. via the ``help`` keyword argument). | trusted_official_docs | CPython Docs | * As should be expected, specifying the long form of the flag, we should get the same output.
* Sadly, our help output isn't very informative on the new ability our script
has acquired, but that can always be fixed by improving the documentation for
our script (e.g. via the ``help`` keyword argument). | * As should be expected, specifying the long form of the flag, we should get the same output.
* Sadly, our help output isn't very informative on the new ability our script
has acquired, but that can always be fixed by improving the documentation for
our script (e.g. via the ``help`` keyword argument). | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6e284624-b5b2-43a7-b5ee-25507f2bb7b5 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,169 | supabase-export-v2 | 2e878def22bda6b4 | familiar with command line usage, you will notice that I haven't yet touched on the topic of short versions of the options. It's quite simple::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", help="increase output verbosity",
action="store_true")
args = parser.parse_args()
... | trusted_official_docs | CPython Docs | familiar with command line usage, you will notice that I haven't yet touched on the topic of short versions of the options. It's quite simple::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", help="increase output verbosity",
action="store_true")
args = parser.parse_args()
... | familiar with command line usage, you will notice that I haven't yet touched on the topic of short versions of the options. It's quite simple::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", help="increase output verbosity",
action="store_true")
args = parser.parse_args()
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6f3f789a-3f15-491e-bc17-dec17876f9f3 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,155 | supabase-export-v2 | 0606e73e784b7470 | * The program is written so as to display something when ``--verbosity`` is specified and display nothing when not.
* To show that the option is actually optional, there is no error when running
the program without it. Note that by default, if an optional argument isn't
used, the relevant variable, in this case ``arg... | trusted_official_docs | CPython Docs | * The program is written so as to display something when ``--verbosity`` is specified and display nothing when not.
* To show that the option is actually optional, there is no error when running
the program without it. Note that by default, if an optional argument isn't
used, the relevant variable, in this case ``arg... | * The program is written so as to display something when ``--verbosity`` is specified and display nothing when not.
* To show that the option is actually optional, there is no error when running
the program without it. Note that by default, if an optional argument isn't
used, the relevant variable, in this case ``arg... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
70cfa944-4fd0-42cd-9edb-867a6de0b6b7 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,197 | supabase-export-v2 | a39646a3ed163e43 | python prog.py 4 -v 1 usage: prog.py [-h] [-v] square prog.py: error: unrecognized arguments: 1 $ python prog.py 4 -h usage: prog.py [-h] [-v] square
positional arguments:
square display a square of a given number | trusted_official_docs | CPython Docs | python prog.py 4 -v 1 usage: prog.py [-h] [-v] square prog.py: error: unrecognized arguments: 1 $ python prog.py 4 -h usage: prog.py [-h] [-v] square
positional arguments:
square display a square of a given number | python prog.py 4 -v 1 usage: prog.py [-h] [-v] square prog.py: error: unrecognized arguments: 1 $ python prog.py 4 -h usage: prog.py [-h] [-v] square
positional arguments:
square display a square of a given number | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
769602e7-8c40-47e4-836b-2930300b748e | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,186 | supabase-export-v2 | d65bba580d9312fa | look good except the last one, which exposes a bug in our program. Let's fix it by restricting the values the ``--verbosity`` option can accept::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", type=int,
help="display a square of a given number")
parser.add_argument("-v", "--verbosi... | trusted_official_docs | CPython Docs | look good except the last one, which exposes a bug in our program. Let's fix it by restricting the values the ``--verbosity`` option can accept::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", type=int,
help="display a square of a given number")
parser.add_argument("-v", "--verbosi... | look good except the last one, which exposes a bug in our program. Let's fix it by restricting the values the ``--verbosity`` option can accept::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", type=int,
help="display a square of a given number")
parser.add_argument("-v", "--verbosi... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
78a356c1-d126-48de-b6bd-15440b496b66 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,158 | supabase-export-v2 | 5020df2f8c701b60 | * When using the ``--verbosity`` option, one must also specify some value, any value.
The above example accepts arbitrary integer values for ``--verbosity``, but for
our simple program, only two values are actually useful, ``True`` or ``False``. Let's modify the code accordingly:: | trusted_official_docs | CPython Docs | * When using the ``--verbosity`` option, one must also specify some value, any value.
The above example accepts arbitrary integer values for ``--verbosity``, but for
our simple program, only two values are actually useful, ``True`` or ``False``. Let's modify the code accordingly:: | * When using the ``--verbosity`` option, one must also specify some value, any value.
The above example accepts arbitrary integer values for ``--verbosity``, but for
our simple program, only two values are actually useful, ``True`` or ``False``. Let's modify the code accordingly:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7cf11201-0c2f-4545-95f9-0beffd31f139 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,153 | supabase-export-v2 | f43548b6081ad04b | help message and exit --verbosity VERBOSITY increase output verbosity $ python prog.py --verbosity usage: prog.py [-h] [--verbosity VERBOSITY] prog.py: error: argument --verbosity: expected one argument
Here is what is happening: | trusted_official_docs | CPython Docs | help message and exit --verbosity VERBOSITY increase output verbosity $ python prog.py --verbosity usage: prog.py [-h] [--verbosity VERBOSITY] prog.py: error: argument --verbosity: expected one argument
Here is what is happening: | help message and exit --verbosity VERBOSITY increase output verbosity $ python prog.py --verbosity usage: prog.py [-h] [--verbosity VERBOSITY] prog.py: error: argument --verbosity: expected one argument
Here is what is happening: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7e6f29d8-b3aa-4686-bb3a-add915ddaf7d | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,130 | supabase-export-v2 | e4ba8fc34e25d6da | to specify which variable that value is stored in). You will also notice that its name matches the string argument given to the method, ``echo``.
Note however that, although the help display looks nice and all, it currently
is not as helpful as it can be. For example we see that we got ``echo`` as a
positional argument... | trusted_official_docs | CPython Docs | to specify which variable that value is stored in). You will also notice that its name matches the string argument given to the method, ``echo``.
Note however that, although the help display looks nice and all, it currently
is not as helpful as it can be. For example we see that we got ``echo`` as a
positional argument... | to specify which variable that value is stored in). You will also notice that its name matches the string argument given to the method, ``echo``.
Note however that, although the help display looks nice and all, it currently
is not as helpful as it can be. For example we see that we got ``echo`` as a
positional argument... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7ee2a218-73ea-4823-8b21-f9163d991c8b | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,214 | supabase-export-v2 | b773aa65e79d8b06 | Let's fix that bug::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", type=int,
help="display a square of a given number")
parser.add_argument("-v", "--verbosity", action="count", default=0,
help="increase output verbosity")
args = parser.parse_args()
answer = args.square**2
if a... | trusted_official_docs | CPython Docs | Let's fix that bug::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", type=int,
help="display a square of a given number")
parser.add_argument("-v", "--verbosity", action="count", default=0,
help="increase output verbosity")
args = parser.parse_args()
answer = args.square**2
if a... | Let's fix that bug::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", type=int,
help="display a square of a given number")
parser.add_argument("-v", "--verbosity", action="count", default=0,
help="increase output verbosity")
args = parser.parse_args()
answer = args.square**2
if a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
800cdad4-9f2a-4c9c-a9d4-8af24f28465c | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,162 | supabase-export-v2 | e1832aa39237f026 | verbosity turned on $ python prog.py --verbose 1 usage: prog.py [-h] [--verbose] prog.py: error: unrecognized arguments: 1 $ python prog.py --help usage: prog.py [-h] [--verbose]
options:
-h, --help show this help message and exit
--verbose increase output verbosity | trusted_official_docs | CPython Docs | verbosity turned on $ python prog.py --verbose 1 usage: prog.py [-h] [--verbose] prog.py: error: unrecognized arguments: 1 $ python prog.py --help usage: prog.py [-h] [--verbose]
options:
-h, --help show this help message and exit
--verbose increase output verbosity | verbosity turned on $ python prog.py --verbose 1 usage: prog.py [-h] [--verbose] prog.py: error: unrecognized arguments: 1 $ python prog.py --help usage: prog.py [-h] [--verbose]
options:
-h, --help show this help message and exit
--verbose increase output verbosity | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
827fca8f-f196-4ff3-82a4-e65b5d021ed6 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,247 | supabase-export-v2 | 4b78f63145d6b175 | follow. I've added that last output so you can see the sort of flexibility you get, i.e. mixing long form options with short form ones.
Before we conclude, you probably want to tell your users the main purpose of
your program, just in case they don't know:: | trusted_official_docs | CPython Docs | follow. I've added that last output so you can see the sort of flexibility you get, i.e. mixing long form options with short form ones.
Before we conclude, you probably want to tell your users the main purpose of
your program, just in case they don't know:: | follow. I've added that last output so you can see the sort of flexibility you get, i.e. mixing long form options with short form ones.
Before we conclude, you probably want to tell your users the main purpose of
your program, just in case they don't know:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8318d709-3a98-40dc-a1ae-12d7eb6b92fb | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,203 | supabase-export-v2 | 33bddeb6e1d349a0 | * And if you don't specify the ``-v`` flag, that flag is considered to have ``None`` value.
* As should be expected, specifying the long form of the flag, we should get
the same output. | trusted_official_docs | CPython Docs | * And if you don't specify the ``-v`` flag, that flag is considered to have ``None`` value.
* As should be expected, specifying the long form of the flag, we should get
the same output. | * And if you don't specify the ``-v`` flag, that flag is considered to have ``None`` value.
* As should be expected, specifying the long form of the flag, we should get
the same output. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
877cece1-528d-42d0-ae52-7e5d70731d7e | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,219 | supabase-export-v2 | f104e47d400d9462 | we have only scratched the surface. The :mod:`argparse` module is very powerful, and we'll explore a bit more of it before we end this tutorial.
Getting a little more advanced
============================== | trusted_official_docs | CPython Docs | we have only scratched the surface. The :mod:`argparse` module is very powerful, and we'll explore a bit more of it before we end this tutorial.
Getting a little more advanced
============================== | we have only scratched the surface. The :mod:`argparse` module is very powerful, and we'll explore a bit more of it before we end this tutorial.
Getting a little more advanced
============================== | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
889e894e-d5ac-4b22-9b40-cc62663cfb92 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,209 | supabase-export-v2 | 9a7a3a816fd899db | # bugfix: replace == with >= if args.verbosity >= 2: print(f"the square of {args.square} equals {answer}") elif args.verbosity >= 1: print(f"{args.square}^2 == {answer}") else: print(answer)
And this is what it gives: | trusted_official_docs | CPython Docs | # bugfix: replace == with >= if args.verbosity >= 2: print(f"the square of {args.square} equals {answer}") elif args.verbosity >= 1: print(f"{args.square}^2 == {answer}") else: print(answer)
And this is what it gives: | # bugfix: replace == with >= if args.verbosity >= 2: print(f"the square of {args.square} equals {answer}") elif args.verbosity >= 1: print(f"{args.square}^2 == {answer}") else: print(answer)
And this is what it gives: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8a7f01f2-3e2e-45b6-8d70-358a4415621f | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,227 | supabase-export-v2 | f62ea5c0b98cac7e | far we've been using verbosity level to *change* the text that gets displayed. The following example instead uses verbosity level to display *more* text instead::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("x", type=int, help="the base")
parser.add_argument("y", type=int, help="the expone... | trusted_official_docs | CPython Docs | far we've been using verbosity level to *change* the text that gets displayed. The following example instead uses verbosity level to display *more* text instead::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("x", type=int, help="the base")
parser.add_argument("y", type=int, help="the expone... | far we've been using verbosity level to *change* the text that gets displayed. The following example instead uses verbosity level to display *more* text instead::
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("x", type=int, help="the base")
parser.add_argument("y", type=int, help="the expone... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8aaa3760-3123-4f0f-8d53-6ae46de4fae7 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,146 | supabase-export-v2 | 1de4585842385abb | $ python prog.py 4 16 $ python prog.py four usage: prog.py [-h] square prog.py: error: argument square: invalid int value: 'four'
That went well. The program now even helpfully quits on bad illegal input
before proceeding. | trusted_official_docs | CPython Docs | $ python prog.py 4 16 $ python prog.py four usage: prog.py [-h] square prog.py: error: argument square: invalid int value: 'four'
That went well. The program now even helpfully quits on bad illegal input
before proceeding. | $ python prog.py 4 16 $ python prog.py four usage: prog.py [-h] square prog.py: error: argument square: invalid int value: 'four'
That went well. The program now even helpfully quits on bad illegal input
before proceeding. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8b5061f6-90c0-444d-97c2-4d080535ff45 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,178 | supabase-export-v2 | da85cdc12f7b104b | .. code-block:: shell-session
$ python prog.py
usage: prog.py [-h] [-v] square
prog.py: error: the following arguments are required: square
$ python prog.py 4
16
$ python prog.py 4 --verbose
the square of 4 equals 16
$ python prog.py --verbose 4
the square of 4 equals 16 | trusted_official_docs | CPython Docs | .. code-block:: shell-session
$ python prog.py
usage: prog.py [-h] [-v] square
prog.py: error: the following arguments are required: square
$ python prog.py 4
16
$ python prog.py 4 --verbose
the square of 4 equals 16
$ python prog.py --verbose 4
the square of 4 equals 16 | .. code-block:: shell-session
$ python prog.py
usage: prog.py [-h] [-v] square
prog.py: error: the following arguments are required: square
$ python prog.py 4
16
$ python prog.py 4 --verbose
the square of 4 equals 16
$ python prog.py --verbose 4
the square of 4 equals 16 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8cd1fbb7-ea8a-4cd5-870a-29556586cd27 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,232 | supabase-export-v2 | 464f3cdea12f0754 | Specifying ambiguous arguments ------------------------------
When there is ambiguity in deciding whether an argument is positional or for an
argument, ``--`` can be used to tell :meth:`~ArgumentParser.parse_args` that
everything after that is a positional argument:: | trusted_official_docs | CPython Docs | Specifying ambiguous arguments ------------------------------
When there is ambiguity in deciding whether an argument is positional or for an
argument, ``--`` can be used to tell :meth:`~ArgumentParser.parse_args` that
everything after that is a positional argument:: | Specifying ambiguous arguments ------------------------------
When there is ambiguity in deciding whether an argument is positional or for an
argument, ``--`` can be used to tell :meth:`~ArgumentParser.parse_args` that
everything after that is a positional argument:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8eae2477-d48a-4c20-92d2-20f86a38b3a4 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,179 | supabase-export-v2 | fbc7f90334188908 | prog.py 4 16 $ python prog.py 4 --verbose the square of 4 equals 16 $ python prog.py --verbose 4 the square of 4 equals 16
* We've brought back a positional argument, hence the complaint. | trusted_official_docs | CPython Docs | prog.py 4 16 $ python prog.py 4 --verbose the square of 4 equals 16 $ python prog.py --verbose 4 the square of 4 equals 16
* We've brought back a positional argument, hence the complaint. | prog.py 4 16 $ python prog.py 4 --verbose the square of 4 equals 16 $ python prog.py --verbose 4 the square of 4 equals 16
* We've brought back a positional argument, hence the complaint. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9271fb37-6aee-4474-8059-605acc22eff9 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,129 | supabase-export-v2 | 03593afc1e35965f | * The :meth:`~ArgumentParser.parse_args` method actually returns some data from the options specified, in this case, ``echo``.
* The variable is some form of 'magic' that :mod:`argparse` performs for free
(i.e. no need to specify which variable that value is stored in). You will also notice that its name matches the s... | trusted_official_docs | CPython Docs | * The :meth:`~ArgumentParser.parse_args` method actually returns some data from the options specified, in this case, ``echo``.
* The variable is some form of 'magic' that :mod:`argparse` performs for free
(i.e. no need to specify which variable that value is stored in). You will also notice that its name matches the s... | * The :meth:`~ArgumentParser.parse_args` method actually returns some data from the options specified, in this case, ``echo``.
* The variable is some form of 'magic' that :mod:`argparse` performs for free
(i.e. no need to specify which variable that value is stored in). You will also notice that its name matches the s... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
93ee653b-18bf-4a7b-8e27-32035061f4cc | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,235 | supabase-export-v2 | d8312325f54ea8e8 | >>> # ambiguous, so parse_args assumes it's an option >>> parser.parse_args(['-f']) usage: PROG [-h] [-n N [N ...]] [args ...] PROG: error: unrecognized arguments: -f
>>> parser.parse_args(['--', '-f'])
Namespace(args=['-f'], n=None) | trusted_official_docs | CPython Docs | >>> # ambiguous, so parse_args assumes it's an option >>> parser.parse_args(['-f']) usage: PROG [-h] [-n N [N ...]] [args ...] PROG: error: unrecognized arguments: -f
>>> parser.parse_args(['--', '-f'])
Namespace(args=['-f'], n=None) | >>> # ambiguous, so parse_args assumes it's an option >>> parser.parse_args(['-f']) usage: PROG [-h] [-n N [N ...]] [args ...] PROG: error: unrecognized arguments: -f
>>> parser.parse_args(['--', '-f'])
Namespace(args=['-f'], n=None) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9bdf3b74-9d51-4e33-915a-a3eb74eac975 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,249 | supabase-export-v2 | 1bf19561f3ab3d89 | import argparse
parser = argparse.ArgumentParser(description="calculate X to the power of Y")
group = parser.add_mutually_exclusive_group()
group.add_argument("-v", "--verbose", action="store_true")
group.add_argument("-q", "--quiet", action="store_true")
parser.add_argument("x", type=int, help="the base")
parser.... | trusted_official_docs | CPython Docs | import argparse
parser = argparse.ArgumentParser(description="calculate X to the power of Y")
group = parser.add_mutually_exclusive_group()
group.add_argument("-v", "--verbose", action="store_true")
group.add_argument("-q", "--quiet", action="store_true")
parser.add_argument("x", type=int, help="the base")
parser.... | import argparse
parser = argparse.ArgumentParser(description="calculate X to the power of Y")
group = parser.add_mutually_exclusive_group()
group.add_argument("-v", "--verbose", action="store_true")
group.add_argument("-q", "--quiet", action="store_true")
parser.add_argument("x", type=int, help="the base")
parser.... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9d61352d-407b-4feb-a920-9599a710f71d | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,103 | supabase-export-v2 | f975351ef3ca9f3f | * The :command:`ls` command is useful when run without any options at all. It defaults to displaying the contents of the current directory.
* If we want beyond what it provides by default, we tell it a bit more. In
this case, we want it to display a different directory, ``pypy``. What we did is specify what is known a... | trusted_official_docs | CPython Docs | * The :command:`ls` command is useful when run without any options at all. It defaults to displaying the contents of the current directory.
* If we want beyond what it provides by default, we tell it a bit more. In
this case, we want it to display a different directory, ``pypy``. What we did is specify what is known a... | * The :command:`ls` command is useful when run without any options at all. It defaults to displaying the contents of the current directory.
* If we want beyond what it provides by default, we tell it a bit more. In
this case, we want it to display a different directory, ``pypy``. What we did is specify what is known a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a2edf07a-0202-4628-a458-acc225b9085c | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,250 | supabase-export-v2 | 17fb4f9e7740e13b | of Y") group = parser.add_mutually_exclusive_group() group.add_argument("-v", "--verbose", action="store_true") group.add_argument("-q", "--quiet", action="store_true") parser.add_argument("x", type=int, help="the base") parser.add_argument("y", type=int, help="the exponent") args = parser.parse_args() answer = args.x*... | trusted_official_docs | CPython Docs | of Y") group = parser.add_mutually_exclusive_group() group.add_argument("-v", "--verbose", action="store_true") group.add_argument("-q", "--quiet", action="store_true") parser.add_argument("x", type=int, help="the base") parser.add_argument("y", type=int, help="the exponent") args = parser.parse_args() answer = args.x*... | of Y") group = parser.add_mutually_exclusive_group() group.add_argument("-v", "--verbose", action="store_true") group.add_argument("-q", "--quiet", action="store_true") parser.add_argument("x", type=int, help="the base") parser.add_argument("y", type=int, help="the exponent") args = parser.parse_args() answer = args.x*... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a3c4eb7b-5e20-4944-8cf6-da8c4cd6a26a | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,116 | supabase-export-v2 | fe1f0f25b68aa47e | The second one starts to display the usefulness of the :mod:`argparse` module. We have done almost nothing, but already we get a nice help message.
* The ``--help`` option, which can also be shortened to ``-h``, is the only
option we get for free (i.e. no need to specify it). Specifying anything
else results in an er... | trusted_official_docs | CPython Docs | The second one starts to display the usefulness of the :mod:`argparse` module. We have done almost nothing, but already we get a nice help message.
* The ``--help`` option, which can also be shortened to ``-h``, is the only
option we get for free (i.e. no need to specify it). Specifying anything
else results in an er... | The second one starts to display the usefulness of the :mod:`argparse` module. We have done almost nothing, but already we get a nice help message.
* The ``--help`` option, which can also be shortened to ``-h``, is the only
option we get for free (i.e. no need to specify it). Specifying anything
else results in an er... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a76f52bb-c56e-4d99-914f-91516fc13ec9 | CPython Docs | file://datasets/cpython/Doc/howto/argparse.rst | unknown | 6466631f-3432-49bd-ad66-8e150a30fc13 | 58,273 | supabase-export-v2 | 98e65c60cb58316b | Once the messages in the ``.po`` file are translated and the translations are installed using :mod:`gettext`, :mod:`argparse` will be able to display the translated messages.
To translate your own strings in the :mod:`argparse` output, use :mod:`gettext`. | trusted_official_docs | CPython Docs | Once the messages in the ``.po`` file are translated and the translations are installed using :mod:`gettext`, :mod:`argparse` will be able to display the translated messages.
To translate your own strings in the :mod:`argparse` output, use :mod:`gettext`. | Once the messages in the ``.po`` file are translated and the translations are installed using :mod:`gettext`, :mod:`argparse` will be able to display the translated messages.
To translate your own strings in the :mod:`argparse` output, use :mod:`gettext`. | python, official-docs, cpython, P0 | Local_Trusted_Corpus |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.