Skip to content

Commit d007fdd

Browse files
committed
Update README
1 parent 71cffad commit d007fdd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,29 @@ After running the above command, the file ``program.py`` will contain the follow
6969
if __name__ == "__main__":
7070
main()
7171
72+
Comma-separated choices for option argument
73+
===========================================
74+
75+
If you have an option which accepts an argument, and you write an argument string with
76+
multiple values separated by commas (e.g. ``-m --mode active,idle,sim``), then ``duckargs``
77+
will use the comma-separated values as a ``choices`` list for argparse, e.g.:
78+
79+
::
80+
81+
parser.add_argument('-m', '--mode', choices=['active', 'idle', 'stim'], default='active', help='a string')
82+
83+
Real filename for option argument
84+
=================================
85+
86+
If you have an option which accepts an argument, and the argument string that you write
87+
happens to be the path to a file that actually exists (e.g. ``-f --filename real_file.txt``),
88+
then ``duckargs`` will tell argparse that this argument is a file, e.g.:
89+
90+
::
91+
92+
parser.add_argument('-f', '--filename', default='real_file.txt', type=argparse.FileType(), help='a filename')
93+
94+
7295
Use duckargs in python code
7396
===========================
7497

0 commit comments

Comments
 (0)