【发布时间】:2019-08-05 06:36:58
【问题描述】:
我正在构建一个 python 模块,如下所示。你可以这样写来使用它:
from color import *
print(color('none', 'red', 'blue') + 'works?')
print(color('none', 'red', 'green') + 'works still?')
代码使用转义码,工作方式如下:
def color(style, fore, bg):
a = "\033[0;"
b = "39;"
c = "49m"
#styles
if style == "none":
a = "\033[0;"
#fore
if fore == "none":
b = "39;"
#background
if bg == "none":
c = "48m"
#finish
return(a + b + c)
“仍在工作”的那一行应该是绿色的,但实际上是蓝色的。
任何想法如何解决这个问题? (如果需要,我可以提供更多代码
【问题讨论】:
-
print(color('none', 'red', 'blue') + 'works\?')你能试试这个吗?print(color('none', 'red', 'green') + 'works still\?') -
是的,如果您将其作为答案提交,我会将其标记为正确
标签: python python-3.x colors terminal module