Why does termcolor output control characters instead of colored text in the Windows console?

前端 未结 5 1448
北恋
北恋 2020-11-28 12:12

I just installed termcolor for Python 2.7 on Windows. When I try to print colored text, I get the color codes instead.

from termcolor import colored
print co         


        
5条回答
  •  一生所求
    2020-11-28 12:24

    Did work :

    inserting previous to importing termcolor:

    import subprocess
    subprocess.call('', shell=True)
    

    Didn't work:

    1. importing colorama (didn't) fix problem - still shows characters
    2. importing / using termcolor2 (didn't) fix problem - still shows
      characters
    3. importing colorama AND termcolor2 AND termcolor (didn't) fix problem.

    Can't explain why it works, only that I was able to compare one script that colors worked correctly, and one that didn't work correctly.

提交回复
热议问题