kennethreitz / crayons

Text UI colors for Python.
https://pypi.python.org/pypi/crayons
MIT License
423 stars 30 forks source link

color funcs generated from __all__ var #17

Closed ghost closed 5 years ago

ghost commented 6 years ago

Instead of defining a function for every color I simply used a for loop for generating them.

(...)
_colors = {x: x.upper() for x in __all__[:-3]}
_colors['normal'] = 'RESET'

for key, val in _colors.items():
    function = eval(
        'lambda s, always=False, bold=False: ColoredString("{}", s, always_color=always, bold=bold)'.format(val))
    locals()[key] = function

del key, val, _colors, function
(...)