Suppose it is the following structure given:
from django.utils.translation import ugettext_lazy as _
# Constants for all available difficulty types.
SIMPLE = 1
MEDIUM = 2
DIFFICULT = 3
# Names for all available difficulty types.
DIFFICULTIES = (
(SIMPLE, _("simple")),
(MEDIUM, _("medium")),
(DIFFICULT, _("difficult")),
)
How do you get the string value, if a constant is given?
A loop is easy to program, but is there a shorter python-like way with a single expression?
The expression
DIFFICULTIES[SIMPLE][1]
returns the string "medium". What is obviously wrong.
dictionary?_("simple")doesn't look like syntactically valid Python to me._function for internationalization (see here).