This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author daverove
Recipients daverove, paul.moore, steve.dower, tim.golden, zach.ware
Date 2020-04-01.11:05:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1585739153.82.0.592216373665.issue40134@roundup.psfhosted.org>
In-reply-to
Content
The correct handling of ANSI escape codes by the print() function may or may not be enabled in the Windows 10 command prompt window, depending on previous system calls. The following is quite repeatable. Comment-out the apparently meaningless os.system("") line and ANSI codes do not work, but leave that line in and ANSI codes DO work:

    import os
    os.system("") # Comment this out to disable ANSI codes
    ansi_red = "\x1b[31m"
    ansi_normal = "\x1b[0m"
    print(ansi_red + "This is red!" + ansi_normal)

To be consistent with Python on Linux and Mac, I believe that ANSI codes should be permanently enabled in Windows 10 rather than removed. ANSI code handling was present from the start of Windows 10, so it's reasonable to presume that it's now a permanent feature of the Windows command prompt window. Either way, the inconsistency of the handling should be fixed.

To emphasize that ANSI codes ARE a feature of the command prompt, comment out that line to disable the ANSI codes in print(), but redirect the output to a text file. Then display that file at the command prompt. The ANSI codes then work correctly. 

    python myansi.py > myansi.txt
    type myansi.txt
History
Date User Action Args
2020-04-01 11:05:53daverovesetrecipients: + daverove, paul.moore, tim.golden, zach.ware, steve.dower
2020-04-01 11:05:53daverovesetmessageid: <1585739153.82.0.592216373665.issue40134@roundup.psfhosted.org>
2020-04-01 11:05:53daverovelinkissue40134 messages
2020-04-01 11:05:53daverovecreate