How can I output colored text to the terminal, in Python? What is the best Unicode symbol to represent a solid block?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Here's a curses example:
On Windows you can use module 'win32console' (available in some Python distributions) or module 'ctypes' (Python 2.5 and up) to access the Win32 API.
To see complete code that supports both ways, see the color console reporting code from Testoob.
ctypes example:
Try this simple code
If you are using Windows, then here you go!
One easier option would be to use the
cprint
function fromtermcolor
package.It also supports
%s, %d
format of printingStupidly simple based on @joeld's answer
Then just