On this page
enum.IntFlag
Prev: enum.IntEnum | Up: enum | Next: enum.member
Rel: enum.auto, enum.Enum, enum.EnumCheck, enum.EnumDict
Ref: docs.python.org — enum.IntFlag
Tags: #public #python3 #stdlib #enum
Import
import enum
from enum import IntFlag
Signature & Overview
enum.IntFlag(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)
Support for integer-based Flags
Methods & Attributes
IntFlag.as_integer_ratio(self, /)— Return a pair of integers, whose ratio is equal to the original int.IntFlag.bit_count(self, /)— Number of ones in the binary representation of the absolute value of self.IntFlag.bit_length(self, /)— Number of bits necessary to represent self in binary.IntFlag.conjugate(self, /)— Returns self, the complex conjugate of any int.IntFlag.from_bytes(bytes, byteorder='big', *, signed=False)— Return the integer represented by the given array of bytes.IntFlag.is_integer(self, /)— Returns True. Exists for duck type compatibility with float.is_integer.IntFlag.to_bytes(self, /, length=1, byteorder='big', *, signed=False)— Return an array of bytes representing an integer.
Usage
from enum import IntFlag
class OpenMode(IntFlag):
READ = 1
WRITE = 2
combo = OpenMode.READ | OpenMode.WRITE
assert combo == 3 and isinstance(combo, int)
Gotchas
- Interoperates with C/OS integer bitmasks: Unlike
Flag,IntFlagmembers areintinstances and can be passed directly to C/OS APIs.
REPL Inspect
from enum import IntFlag
help(IntFlag)
Linked from
Related notes
- tuts/python3/stdlib_module/enum/IntEnum Linked here; links to this page; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/member Linked here; links to this page; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/auto Linked here; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/Enum Linked here; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/EnumCheck Linked here; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/EnumDict Linked here; shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/enum/EnumMeta shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/EnumType shared tags: #enum, #stdlib
- tuts/python3/stdlib_module/enum/Flag shared tags: #enum, #stdlib