2024-09-30 05:31:50 发布
网友
我正在使用单击模块
pip install click
这给了我红色文本
import click click.secho('Error: This error is ...xx', fg='red')
现在我只希望“Error:”显示为红色。如何使用click.secho实现这一点
click.secho
来自echo method的click文档
click
In addition to that, if colorama is installed, the echo function will also support clever handling of ANSI codes.
来自^{}文档
print('\033[31m' + 'some red text') print('\033[30m') # and reset to default color
因此,结合起来,您应该有如下内容
click.echo('\033[31m' + 'Error:' + '\033[30m' + ' This error ... ')
为了得到你想要的东西
您可以使用带有nl(新行)标志的内置secho命令
nl
secho
在您的特定用例中
click.secho('Error', fg='red', nl=False) # This will prevent the secho statement from starting a new line click.echo(': This error is ...xx')
这将为您提供所需的输出
将click.echo与click.style一起使用
click.echo
click.style
click.echo(click.style("Error", fg="red") + ": This error is...")
来自echo method的
click
文档来自^{} 文档
因此,结合起来,您应该有如下内容
为了得到你想要的东西
您可以使用带有
nl
(新行)标志的内置secho
命令在您的特定用例中
这将为您提供所需的输出
将
click.echo
与click.style
一起使用相关问题 更多 >
编程相关推荐