Skip to main content

argparses

番风Less than 1 minute

命令行交互的核心

相关文档

argparse — Parser for command-line options, arguments and sub-commandsopen in new window

Argparse

NameDescriptionValues
actionopen in new windowSpecify how an argument should be handled'store''store_const''store_true''append''append_const''count''help''version'
choicesopen in new windowLimit values to a specific set of choices['foo', 'bar']range(1, 10), or Containeropen in new window instance
constopen in new windowStore a constant value
defaultopen in new windowDefault value used when an argument is not providedDefaults to None
destopen in new windowSpecify the attribute name used in the result namespace
helpopen in new windowHelp message for an argument
metavaropen in new windowAlternate display name for the argument as shown in help
nargsopen in new windowNumber of times the argument can be usedintopen in new window'?''*', or '+'
requiredopen in new windowIndicate whether an argument is required or optionalTrue or False
typeopen in new windowAutomatically convert an argument to the given typeintopen in new windowfloatopen in new windowargparse.FileType('w'), or callable function