Python Glossary Русский

Python 3.11+enumfunction

enum.global_enum_repr

globalization

The repr function for members of a global_enum-decorated enum (shows module.MEMBER).

Syntax

enum.global_enum_repr(member)

You almost never call this yourself: global_enum installs it as the class's __repr__, and the function is only interesting if you write a similar decorator of your own. The module prefix comes from the enum class's own __module__, so re-exporting a member elsewhere still shows the module where the enum was defined.

Examples

import enum, re
print(callable(enum.global_enum_repr))   # → True
print(enum.global_enum_repr(enum.FlagBoundary.STRICT))   # → enum.STRICT
print(enum.global_enum_repr(re.RegexFlag.IGNORECASE))   # → re.IGNORECASE
print(repr(re.IGNORECASE))   # → re.IGNORECASE
import enum, re
class Color(enum.Enum): RED = 1
print(repr(Color.RED))   # → <Color.RED: 1>

See also

Open in the full glossarydocs.python.orgReport an inaccuracy