4 ms·
Clint, Command Line Library for Python
- statictype 15y agoSomething about the colored.red(txt) syntax bothers me. Shouldn't color should really be a parameter - unless the console only accepts a fixed set of colors? I like the rest of it - using a 'with' block for indentation is clever.
- brown9-2 15y agoLooks to me like colored.red(string) just calls ColoredString(color, string), so you could use that version if you want to parameterize the color argument. print ColoredString("red", "some text")
- crazydiamond 15y agoYes, I've seen a bunch of shell and perl utilities that use this approach. You can't use them when you want 256 colors. You can check http://cbouvi.free.fr/download/colorize/ http://cbouvi.free.fr/download/colorize/ and http://code.google.com/p/ansi-color/ http://code.google.com/p/ansi-color/. Ruby has highline and colored, and perhaps some more too.
- kenneth_reitz 15y agoThere's an experimental branch with 256 support. Fallback isn't simple though.
- icebraining 15y agoWell, there's nothing wrong with providing a shortcut, although personally I would have preferred a closure: printred = colored.print_function("red") printred("This prints in red")
- j_baker 15y agoWouldn't this work? I can't test it at the moment. print_function = lambda c: getattr(colored, c) printred = colored.print_function("red") printred("This prints in red")
- DevX101 15y agohttp://pypi.python.org/pypi/termcolor http://pypi.python.org/pypi/termcolor print colored('Hello, World!', 'red')
- kenneth_reitz 15y agofrom clint.textui.color import red, blue, green print "{0}, {1}, and {2}".format(red('red'), blue('blue'), green('green'))
- g3orge 15y agoJust released for Python 3 as well.
- deleted 15y ago[deleted]
- deleted 15y ago[deleted]