1

可能你们中的一些人都知道并且关于 shell 脚本 - tputis 实用程序使用 terminfo 数据库来使 shell 可以使用终端相关功能的值和信息

在我的python脚本中,我有以下示例:(只是长代码中的一个示例)

for TOPIC in list:
  if str(val) in TOPIC:
     word = TOPIC.split()[1]
     print ("Topic " + word + " is successfully configured")
  else:
      try:
       word = TOPIC.split()[1]
       print ("Topic " + word + " bad configuration")
      except IndexError:
       pass

我想在以下打印中将颜色从白色更改为绿色:

 print ("Topic " + word + " is successfully configured")

或将颜色从白色更改为红色

print ("Topic " + word + " bad configuration")

是否可以像我们在脚本中所做的那样更改颜色?python3bash

4

1 回答 1

2
import os
os.system("")

RED = "\x1B["
GREEN = '\033[32m'

word = "random_topic_name"
print(GREEN+"Topic " + word + "successfully configured" )
print(RED+"Topic " + word + "bad configuration" )
于 2021-09-12T18:00:33.030 回答