Attend the Women in ML Symposium on December 7 Register now


Stay organized with collections Save and categorize content based on your preferences.

Registry of :class:~absl.flags.Flag objects.

A :class:FlagValues can then scan command line arguments, passing flag arguments through to the 'Flag' objects that it owns. It also provides easy access to the flag values. Typically only one :class:FlagValues object is needed by an application: :const:FLAGS.

This class is heavily overloaded:

:class:Flag objects are registered via __setitem__::

 FLAGS['longname'] = x   # register a new flag

The .value attribute of the registered :class:~absl.flags.Flag objects can be accessed as attributes of this :class:FlagValues object, through __getattr__. Both the long and short name of the original :class:~absl.flags.Flag objects can be used to access its value::

 FLAGS.longname  # parsed flag value
 FLAGS.x  # parsed flag value (short name)

Command line arguments are scanned and passed to the registered :class:~absl.flags.Flag objects through the __call__ method. Unparsed arguments, including argv[0] (e.g. the program name) are returned::

 argv = FLAGS(sys.argv)  # scan command line arguments

The original registered :class:~absl.flags.Flag objects can be retrieved through the use of the dictionary-like operator, __getitem__::

 x = FLAGS['longname']   # access the registered Flag object

The str() operator of a :class:absl.flags.FlagValues object provides help for all of the registered :class:~absl.flags.Flag objects.