File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -1133,6 +1133,20 @@ container should match the type_ specified::
1133
1133
1134
1134
Any container can be passed as the *choices * value, so :class: `list ` objects,
1135
1135
:class: `set ` objects, and custom containers are all supported.
1136
+ This includes :class: `enum.Enum `, which could be used to restrain
1137
+ argument's choices; if we reuse previous rock/paper/scissors game example,
1138
+ this could be as follows::
1139
+
1140
+ >>> from enum import Enum
1141
+ >>> class GameMove(Enum):
1142
+ ... ROCK = 'rock'
1143
+ ... PAPER = 'paper'
1144
+ ... SCISSORS = 'scissors'
1145
+ ...
1146
+ >>> parser = argparse.ArgumentParser(prog='game.py')
1147
+ >>> parser.add_argument('move', type=GameMove, choices=GameMove)
1148
+ >>> parser.parse_args(['rock'])
1149
+ Namespace(move=<GameMove.ROCK: 'rock'>)
1136
1150
1137
1151
1138
1152
required
You can’t perform that action at this time.
0 commit comments