On this page
enum.auto
Up: enum | Next: enum.Enum
Rel: enum.Enum, enum.EnumCheck, enum.EnumDict, enum.EnumMeta
Ref: docs.python.org — enum.auto
Tags: #public #python3 #stdlib #enum
Import
import enum
from enum import auto
Signature & Overview
enum.auto(value=_auto_null)
Instances are replaced with an appropriate value in Enum class suites.
Usage
from enum import Enum, auto
class Color(Enum):
RED = auto()
GREEN = auto()
BLUE = auto()
assert [c.value for c in Color] == [1, 2, 3]
Gotchas
- Behavior depends on the base class:
Enum/IntEnumassign1, 2, 3...;Flag/IntFlagassign powers of two1, 2, 4...;StrEnumassigns lowercase member names. - Don't mix
auto()with explicit values carelessly: Customize_generate_next_value_if you need custom auto-numbering.
REPL Inspect
from enum import auto
help(auto)
Linked from
- tuts/python3/stdlib_module/enum
- tuts/python3/stdlib_module/enum/Enum
- tuts/python3/stdlib_module/enum/EnumCheck
- tuts/python3/stdlib_module/enum/EnumDict
- tuts/python3/stdlib_module/enum/EnumMeta
- tuts/python3/stdlib_module/enum/EnumType
- tuts/python3/stdlib_module/enum/Flag
- tuts/python3/stdlib_module/enum/FlagBoundary
- tuts/python3/stdlib_module/enum/global_enum
- tuts/python3/stdlib_module/enum/global_enum_repr
- tuts/python3/stdlib_module/enum/global_flag_repr
- tuts/python3/stdlib_module/enum/global_str
- tuts/python3/stdlib_module/enum/IntEnum
- tuts/python3/stdlib_module/enum/IntFlag
- tuts/python3/stdlib_module/enum/member
- tuts/python3/stdlib_module/enum/nonmember
- tuts/python3/stdlib_module/enum/pickle_by_enum_name
- tuts/python3/stdlib_module/enum/pickle_by_global_name
- tuts/python3/stdlib_module/enum/property
- tuts/python3/stdlib_module/enum/ReprEnum
- tuts/python3/stdlib_module/enum/StrEnum
- tuts/python3/stdlib_module/enum/unique
- tuts/python3/stdlib_module/enum/verify
Related notes
- tuts/python3/stdlib_module/enum/Enum Linked here; links to this page; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/EnumCheck Linked here; links to this page; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/EnumDict Linked here; links to this page; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/EnumMeta Linked here; links to this page; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/EnumType links to this page; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/Flag links to this page; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/FlagBoundary links to this page; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/global_enum links to this page; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/global_enum_repr links to this page; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/global_flag_repr links to this page; shared tags: #enum, #stdlib