当尝试从包含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 ,但结果相同