Get Value Of An Enum
Environment
- Pythonnet version: latest
- Python version: 3.9.4
- Operating System: Windows
- .NET Runtime:
Details
- Describe what you were trying to get done.
I would like to have the ability to extract the value of a .Net Enum via python. One can do that using MyEnum.value__, however it seems logical that you should do it using int(MyEnum).
- What commands did you run to trigger this issue? If you can provide a
Minimal, Complete, and Verifiable example
this will help us understand the issue.
import clr clr.AddReference("System.Windows.Forms") import System.Windows.Forms as WinForms enum_value = WinForms.Keys.Control print(f"{enum_value=}") print(f"{enum_value.value__=}")
That prints:
enum_value=<System.Windows.Forms.Keys object at 0x000001C053E07580>
enum_value.value__=131072
- If there was a crash, please include the traceback here.
No crash.