@@ -79,16 +79,16 @@ Following is a result of running the code:
79
79
80
80
.. code-block :: shell-session
81
81
82
- $ python3 prog.py
83
- $ python3 prog.py --help
82
+ $ python prog.py
83
+ $ python prog.py --help
84
84
usage: prog.py [-h]
85
85
86
86
options:
87
87
-h, --help show this help message and exit
88
- $ python3 prog.py --verbose
88
+ $ python prog.py --verbose
89
89
usage: prog.py [-h]
90
90
prog.py: error: unrecognized arguments: --verbose
91
- $ python3 prog.py foo
91
+ $ python prog.py foo
92
92
usage: prog.py [-h]
93
93
prog.py: error: unrecognized arguments: foo
94
94
@@ -121,18 +121,18 @@ And running the code:
121
121
122
122
.. code-block :: shell-session
123
123
124
- $ python3 prog.py
124
+ $ python prog.py
125
125
usage: prog.py [-h] echo
126
126
prog.py: error: the following arguments are required: echo
127
- $ python3 prog.py --help
127
+ $ python prog.py --help
128
128
usage: prog.py [-h] echo
129
129
130
130
positional arguments:
131
131
echo
132
132
133
133
options:
134
134
-h, --help show this help message and exit
135
- $ python3 prog.py foo
135
+ $ python prog.py foo
136
136
foo
137
137
138
138
Here is what's happening:
@@ -166,7 +166,7 @@ And we get:
166
166
167
167
.. code-block :: shell-session
168
168
169
- $ python3 prog.py -h
169
+ $ python prog.py -h
170
170
usage: prog.py [-h] echo
171
171
172
172
positional arguments:
@@ -187,7 +187,7 @@ Following is a result of running the code:
187
187
188
188
.. code-block :: shell-session
189
189
190
- $ python3 prog.py 4
190
+ $ python prog.py 4
191
191
Traceback (most recent call last):
192
192
File "prog.py", line 5, in <module>
193
193
print(args.square**2)
@@ -208,9 +208,9 @@ Following is a result of running the code:
208
208
209
209
.. code-block :: shell-session
210
210
211
- $ python3 prog.py 4
211
+ $ python prog.py 4
212
212
16
213
- $ python3 prog.py four
213
+ $ python prog.py four
214
214
usage: prog.py [-h] square
215
215
prog.py: error: argument square: invalid int value: 'four'
216
216
@@ -235,17 +235,17 @@ And the output:
235
235
236
236
.. code-block :: shell-session
237
237
238
- $ python3 prog.py --verbosity 1
238
+ $ python prog.py --verbosity 1
239
239
verbosity turned on
240
- $ python3 prog.py
241
- $ python3 prog.py --help
240
+ $ python prog.py
241
+ $ python prog.py --help
242
242
usage: prog.py [-h] [--verbosity VERBOSITY]
243
243
244
244
options:
245
245
-h, --help show this help message and exit
246
246
--verbosity VERBOSITY
247
247
increase output verbosity
248
- $ python3 prog.py --verbosity
248
+ $ python prog.py --verbosity
249
249
usage: prog.py [-h] [--verbosity VERBOSITY]
250
250
prog.py: error: argument --verbosity: expected one argument
251
251
@@ -281,12 +281,12 @@ And the output:
281
281
282
282
.. code-block :: shell-session
283
283
284
- $ python3 prog.py --verbose
284
+ $ python prog.py --verbose
285
285
verbosity turned on
286
- $ python3 prog.py --verbose 1
286
+ $ python prog.py --verbose 1
287
287
usage: prog.py [-h] [--verbose]
288
288
prog.py: error: unrecognized arguments: 1
289
- $ python3 prog.py --help
289
+ $ python prog.py --help
290
290
usage: prog.py [-h] [--verbose]
291
291
292
292
options:
@@ -327,9 +327,9 @@ And here goes:
327
327
328
328
.. code-block :: shell-session
329
329
330
- $ python3 prog.py -v
330
+ $ python prog.py -v
331
331
verbosity turned on
332
- $ python3 prog.py --help
332
+ $ python prog.py --help
333
333
usage: prog.py [-h] [-v]
334
334
335
335
options:
@@ -361,14 +361,14 @@ And now the output:
361
361
362
362
.. code-block :: shell-session
363
363
364
- $ python3 prog.py
364
+ $ python prog.py
365
365
usage: prog.py [-h] [-v] square
366
366
prog.py: error: the following arguments are required: square
367
- $ python3 prog.py 4
367
+ $ python prog.py 4
368
368
16
369
- $ python3 prog.py 4 --verbose
369
+ $ python prog.py 4 --verbose
370
370
the square of 4 equals 16
371
- $ python3 prog.py --verbose 4
371
+ $ python prog.py --verbose 4
372
372
the square of 4 equals 16
373
373
374
374
* We've brought back a positional argument, hence the complaint.
@@ -397,16 +397,16 @@ And the output:
397
397
398
398
.. code-block :: shell-session
399
399
400
- $ python3 prog.py 4
400
+ $ python prog.py 4
401
401
16
402
- $ python3 prog.py 4 -v
402
+ $ python prog.py 4 -v
403
403
usage: prog.py [-h] [-v VERBOSITY] square
404
404
prog.py: error: argument -v/--verbosity: expected one argument
405
- $ python3 prog.py 4 -v 1
405
+ $ python prog.py 4 -v 1
406
406
4^2 == 16
407
- $ python3 prog.py 4 -v 2
407
+ $ python prog.py 4 -v 2
408
408
the square of 4 equals 16
409
- $ python3 prog.py 4 -v 3
409
+ $ python prog.py 4 -v 3
410
410
16
411
411
412
412
These all look good except the last one, which exposes a bug in our program.
@@ -431,10 +431,10 @@ And the output:
431
431
432
432
.. code-block :: shell-session
433
433
434
- $ python3 prog.py 4 -v 3
434
+ $ python prog.py 4 -v 3
435
435
usage: prog.py [-h] [-v {0,1,2}] square
436
436
prog.py: error: argument -v/--verbosity: invalid choice: 3 (choose from 0, 1, 2)
437
- $ python3 prog.py 4 -h
437
+ $ python prog.py 4 -h
438
438
usage: prog.py [-h] [-v {0,1,2}] square
439
439
440
440
positional arguments:
@@ -473,18 +473,18 @@ to count the number of occurrences of specific options.
473
473
474
474
.. code-block :: shell-session
475
475
476
- $ python3 prog.py 4
476
+ $ python prog.py 4
477
477
16
478
- $ python3 prog.py 4 -v
478
+ $ python prog.py 4 -v
479
479
4^2 == 16
480
- $ python3 prog.py 4 -vv
480
+ $ python prog.py 4 -vv
481
481
the square of 4 equals 16
482
- $ python3 prog.py 4 --verbosity --verbosity
482
+ $ python prog.py 4 --verbosity --verbosity
483
483
the square of 4 equals 16
484
- $ python3 prog.py 4 -v 1
484
+ $ python prog.py 4 -v 1
485
485
usage: prog.py [-h] [-v] square
486
486
prog.py: error: unrecognized arguments: 1
487
- $ python3 prog.py 4 -h
487
+ $ python prog.py 4 -h
488
488
usage: prog.py [-h] [-v] square
489
489
490
490
positional arguments:
@@ -493,7 +493,7 @@ to count the number of occurrences of specific options.
493
493
options:
494
494
-h, --help show this help message and exit
495
495
-v, --verbosity increase output verbosity
496
- $ python3 prog.py 4 -vvv
496
+ $ python prog.py 4 -vvv
497
497
16
498
498
499
499
* Yes, it's now more of a flag (similar to ``action="store_true" ``) in the
@@ -540,11 +540,11 @@ And this is what it gives:
540
540
541
541
.. code-block :: shell-session
542
542
543
- $ python3 prog.py 4 -vvv
543
+ $ python prog.py 4 -vvv
544
544
the square of 4 equals 16
545
- $ python3 prog.py 4 -vvvv
545
+ $ python prog.py 4 -vvvv
546
546
the square of 4 equals 16
547
- $ python3 prog.py 4
547
+ $ python prog.py 4
548
548
Traceback (most recent call last):
549
549
File "prog.py", line 11, in <module>
550
550
if args.verbosity >= 2:
584
584
585
585
.. code-block :: shell-session
586
586
587
- $ python3 prog.py 4
587
+ $ python prog.py 4
588
588
16
589
589
590
590
You can go quite far just with what we've learned so far,
@@ -617,10 +617,10 @@ Output:
617
617
618
618
.. code-block :: shell-session
619
619
620
- $ python3 prog.py
620
+ $ python prog.py
621
621
usage: prog.py [-h] [-v] x y
622
622
prog.py: error: the following arguments are required: x, y
623
- $ python3 prog.py -h
623
+ $ python prog.py -h
624
624
usage: prog.py [-h] [-v] x y
625
625
626
626
positional arguments:
@@ -630,7 +630,7 @@ Output:
630
630
options:
631
631
-h, --help show this help message and exit
632
632
-v, --verbosity
633
- $ python3 prog.py 4 2 -v
633
+ $ python prog.py 4 2 -v
634
634
4^2 == 16
635
635
636
636
@@ -655,11 +655,11 @@ Output:
655
655
656
656
.. code-block :: shell-session
657
657
658
- $ python3 prog.py 4 2
658
+ $ python prog.py 4 2
659
659
16
660
- $ python3 prog.py 4 2 -v
660
+ $ python prog.py 4 2 -v
661
661
4^2 == 16
662
- $ python3 prog.py 4 2 -vv
662
+ $ python prog.py 4 2 -vv
663
663
Running 'prog.py'
664
664
4^2 == 16
665
665
@@ -727,16 +727,16 @@ demonstration. Anyways, here's the output:
727
727
728
728
.. code-block :: shell-session
729
729
730
- $ python3 prog.py 4 2
730
+ $ python prog.py 4 2
731
731
4^2 == 16
732
- $ python3 prog.py 4 2 -q
732
+ $ python prog.py 4 2 -q
733
733
16
734
- $ python3 prog.py 4 2 -v
734
+ $ python prog.py 4 2 -v
735
735
4 to the power 2 equals 16
736
- $ python3 prog.py 4 2 -vq
736
+ $ python prog.py 4 2 -vq
737
737
usage: prog.py [-h] [-v | -q] x y
738
738
prog.py: error: argument -q/--quiet: not allowed with argument -v/--verbose
739
- $ python3 prog.py 4 2 -v --quiet
739
+ $ python prog.py 4 2 -v --quiet
740
740
usage: prog.py [-h] [-v | -q] x y
741
741
prog.py: error: argument -q/--quiet: not allowed with argument -v/--verbose
742
742
@@ -771,7 +771,7 @@ but not both at the same time:
771
771
772
772
.. code-block :: shell-session
773
773
774
- $ python3 prog.py --help
774
+ $ python prog.py --help
775
775
usage: prog.py [-h] [-v | -q] x y
776
776
777
777
calculate X to the power of Y
0 commit comments