The only public method of a Flag object is :meth:parse, but it is
typically only called by a :class:~absl.flags.FlagValues object. The
:meth:parse method is a thin wrapper around the
:meth:ArgumentParser.parse()<absl.flags.ArgumentParser.parse> method. The
parsed value is saved in .value, and the .present attribute is
updated. If this flag was already present, an Error is raised.
:meth:parse is also called during __init__ to parse the default value
and initialize the .value attribute. This enables other python modules to
safely use flags even if the __main__ module neglects to parse the
command line arguments. The .present attribute is cleared after
__init__ parsing. If the default value is set to None, then the
__init__ parsing step is skipped and the .value attribute is
initialized to None.
Attributes
name
the name for this flag
default
the default value for this flag
default_unparsed
the unparsed default value for this flag.
default_as_str
default value as repr'd string, e.g., "'true'"
(or None)
value
the most recent parsed value of this flag set by :meth:parse
help
a help string or None if no help is available
short_name
the single letter alias for this flag (or None)
boolean
if 'true', this flag does not accept arguments
present
true if this flag was parsed from command line flags
parser
an :class:~absl.flags.ArgumentParser object
serializer
an ArgumentSerializer object
allow_override
the flag may be redefined without raising an error,
and newly defined flag overrides the old one.
allow_override_cpp
use the flag from C++ if available the flag
definition is replaced by the C++ flag after init
allow_hide_cpp
use the Python flag despite having a C++ flag with
the same name (ignore the C++ flag)
using_default_value
the flag value has not been set by user
allow_overwrite
the flag may be parsed more than once without
raising an error, the last set value will be used
allow_using_method_names
whether this flag can be defined even if
it has a name that conflicts with a FlagValues method.
validators
list of the flag validators.
Methods
flag_type
flag_type()->Text
Returns a str that describes the type of the flag.
parse
parse(argument:Union[Text,Optional[_T]])->None
Parses string and sets flag value.
Args
argument
str or the correct flag value type, argument to be parsed.
serialize
serialize()->Text
Serializes the flag.
unparse
unparse()->None
__bool__
__bool__()
__eq__
__eq__(other)
Return self==value.
__ge__
__ge__(other,NotImplemented=NotImplemented)
Return a >= b. Computed by @total_ordering from (not a < b).
__gt__
__gt__(other,NotImplemented=NotImplemented)
Return a > b. Computed by @total_ordering from (not a < b) and (a != b).
__le__
__le__(other,NotImplemented=NotImplemented)
Return a <= b. Computed by @total_ordering from (a < b) or (a == b).
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.compat.v1.flags.Flag\n\n\u003cbr /\u003e\n\nInformation about a command-line flag. \n\n tf.compat.v1.flags.Flag(\n parser: _argument_parser.ArgumentParser[_T],\n serializer: Optional[_argument_parser.ArgumentSerializer[_T]],\n name: Text,\n default: Union[Optional[_T], Text],\n help_string: Optional[Text],\n short_name: Optional[Text] = None,\n boolean: bool = False,\n allow_override: bool = False,\n allow_override_cpp: bool = False,\n allow_hide_cpp: bool = False,\n allow_overwrite: bool = True,\n allow_using_method_names: bool = False\n ) -\u003e None\n\nThe only public method of a `Flag` object is :meth:`parse`, but it is\ntypically only called by a :class:`~absl.flags.FlagValues` object. The\n:meth:`parse` method is a thin wrapper around the\n:meth:`ArgumentParser.parse()\u003cabsl.flags.ArgumentParser.parse\u003e` method. The\nparsed value is saved in `.value`, and the `.present` attribute is\nupdated. If this flag was already present, an Error is raised.\n\n:meth:`parse` is also called during `__init__` to parse the default value\nand initialize the `.value` attribute. This enables other python modules to\nsafely use flags even if the `__main__` module neglects to parse the\ncommand line arguments. The `.present` attribute is cleared after\n`__init__` parsing. If the default value is set to `None`, then the\n`__init__` parsing step is skipped and the `.value` attribute is\ninitialized to None.\n| **Note:** The default value is also presented to the user in the help string, so it is important that it be a legal value for this flag.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|----------------------------|---------------------------------------------------------------------------------------------------|\n| `name` | the name for this flag |\n| `default` | the default value for this flag |\n| `default_unparsed` | the unparsed default value for this flag. |\n| `default_as_str` | default value as repr'd string, e.g., \"'true'\" (or None) |\n| `value` | the most recent parsed value of this flag set by :meth:`parse` |\n| `help` | a help string or None if no help is available |\n| `short_name` | the single letter alias for this flag (or None) |\n| `boolean` | if 'true', this flag does not accept arguments |\n| `present` | true if this flag was parsed from command line flags |\n| `parser` | an :class:`~absl.flags.ArgumentParser` object |\n| `serializer` | an ArgumentSerializer object |\n| `allow_override` | the flag may be redefined without raising an error, and newly defined flag overrides the old one. |\n| `allow_override_cpp` | use the flag from C++ if available the flag definition is replaced by the C++ flag after init |\n| `allow_hide_cpp` | use the Python flag despite having a C++ flag with the same name (ignore the C++ flag) |\n| `using_default_value` | the flag value has not been set by user |\n| `allow_overwrite` | the flag may be parsed more than once without raising an error, the last set value will be used |\n| `allow_using_method_names` | whether this flag can be defined even if it has a name that conflicts with a FlagValues method. |\n| `validators` | list of the flag validators. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `flag_type`\n\n flag_type() -\u003e Text\n\nReturns a str that describes the type of the flag.\n| **Note:** we use strings, and not the types.\\*Type constants because our flags can have more exotic types, e.g., 'comma separated list of strings', 'whitespace separated list of strings', etc.\n\n### `parse`\n\n parse(\n argument: Union[Text, Optional[_T]]\n ) -\u003e None\n\nParses string and sets flag value.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|------------|------------------------------------------------------------|\n| `argument` | str or the correct flag value type, argument to be parsed. |\n\n\u003cbr /\u003e\n\n### `serialize`\n\n serialize() -\u003e Text\n\nSerializes the flag.\n\n### `unparse`\n\n unparse() -\u003e None\n\n### `__bool__`\n\n __bool__()\n\n### `__eq__`\n\n __eq__(\n other\n )\n\nReturn self==value.\n\n### `__ge__`\n\n __ge__(\n other, NotImplemented=NotImplemented\n )\n\nReturn a \\\u003e= b. Computed by @total_ordering from (not a \\\u003c b).\n\n### `__gt__`\n\n __gt__(\n other, NotImplemented=NotImplemented\n )\n\nReturn a \\\u003e b. Computed by @total_ordering from (not a \\\u003c b) and (a != b).\n\n### `__le__`\n\n __le__(\n other, NotImplemented=NotImplemented\n )\n\nReturn a \\\u003c= b. Computed by @total_ordering from (a \\\u003c b) or (a == b).\n\n### `__lt__`\n\n __lt__(\n other\n )\n\nReturn self\\\u003cvalue."]]