Cast int to enum in Python for my program? -


how can int cast enum in python?

if want flexibility convert between int , enum, can use enum.intenum

import enum  class color(enum.intenum):     green = 1     blue = 2     red = 3     yellow = 4  color_code = 4 # cast enum color = color(color_code)  # cast int color_code = int(color) 

note: if using python<3.4, enum has been backported, need install it, e.g. via pip install enum

more on enums in python - https://docs.python.org/3/library/enum.html


Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -