Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python enum key string get

from enum import Enum

class Status(Enum):
    STATUS_OK = 0
    STATUS_ERR_NULL_POINTER = 1 
    STATUS_ERR_INVALID_PARAMETER = 2

    #giving you access to the name and value:

name = Status(1).name  # gives 'STATUS_ERR_NULL_POINTER'
value = Status.STATUS_ERR_NULL_POINTER.value  # gives 1


or

#You'd have to loop through the class attributes to find the matching name:
name = next(name for name, value in vars(Status).items() if value == 1)
Comment

PREVIOUS NEXT
Code Example
Python :: Get Result From Table Django 
Python :: Create New Entry Into Table Django 
Python :: Reading Excel and other Microsoft Office files 
Python :: dynamic list in python 
Python :: get database image in dajngo 
Python :: is tkinter built into python 
Python :: qr code scanner on django 
Python :: os cd python 
Python :: Implementing Java-style getters and setters in Python 
Python :: change y axis scale python 
Python :: Python - Perl - Tcl 
Python :: python two list into dictinaray list comprehension 
Python :: display calendar 
Python :: django create view template 
Python :: importare un foglio di un file excel in python 
Python :: 90/360 
Python :: pyfiglet not coming up cmd 
Python :: datetime day deutsch python 
Python :: c# script for download music from telegram channel 
Python :: how to convert csv columns to text python 
Python :: tkinter lottery app 
Python :: assert_series_equal 
Python :: sqlalchemy create engine SQLite Absolute 
Python :: python for schleife 
Python :: install plotly manually 
Python :: how can you make a data fram 
Python :: do function for each 10sec with pyside2 
Python :: Generate bootstrap replicate of 1D data that return a particular operation on a range 
Python :: dict get keys tcl 
Python :: iterate over k values and plot the inertia values for each k 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =