Not sure if this has been asked before or not. Its a bit of an odd question, so I'll go ahead and fire away.
I've got some variable (or rather constant) definitions:
# Constants # Colors RED="RED" ORANGE="ORANGE" YELLOW="YELLOW" GREEN="GREEN" CYAN="CYAN" BLUE="BLUE" MAGENTA="MAGENTA" # Modes PANIC="PANIC" SOLID="SOLID" BREATHING="BREATHING" # Special sub-modes (for panic) BLINKING="BLINKING" # Declare them SOLID_RED="{}_{}".format(SOLID,RED) SOLID_BLUE="{}_{}".format(SOLID,BLUE) SOLID_MAGENTA="{}_{}".format(SOLID,MAGENTA) ## .. BREATHING_RED="{}_{}".format(BREATHING,RED) BREATHING_BLUE="{}_{}".format(BREATHING,BLUE) BREATHING_MAGENTA="{}_{}".format(BREATHING,MAGENTA) ## .. PANIC_RED="{}_{}".format(PANIC,RED) PANIC_BLUE="{}_{}".format(PANIC,BLUE) PANIC_MAGENTA="{}_{}".format(PANIC,MAGENTA) ## .. PANIC_BLINKING="{}_{}".format(PANIC,BLINKING) I got a lot of definitions! Instead of having to type them all out like this, would there be a way for me to just construct all these constants into existence as strings only using the definitions BEFORE # declare them , or by using, say, a dictionary?
The format I'd need for such a iterative construction is: MODE_COLOR naming convention.
I require that this answer works using Python 2.7. As I have some dependent 2.7 APIs included.