文本文件中的ANSI Escape颜色代码无法正确打印

问题描述

当尝试从包含ANSI转义颜色代码文件中读取文本时,它只会打印颜色代码而不会显示颜色

这已在Windows 10和MSYS中进行了测试

文本文件(title.txt):\033[0;32m Example \033[0m

代码

def showtext():
    ## Declare the path of the title
    titlePath = r'display\title.txt'

    ## Try to read the title from the given text
    try:
        ## Open the file in read mode
        f = io.open(titlePath,mode="r",encoding="ascii")
    
        ## Print the read text
        print(f.read())

    except (IOError,OSError) as e:
        print("Could not read text")

文本输出\033[0;32m Example \033[0m

打印: [1]:https://i.stack.imgur.com/se4MS.png

我还尝试导入和初始化 colorama 并使用 termcolor cprint ,但结果相同

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)