2024-09-30 05:27:14 发布
网友
我用的是点击模块。在
pip install click
这给了我红色的文本
现在我希望只有“Error:”显示为红色。如何使用click.secho来完成此操作?在
click.secho
您可以使用内置的secho命令和nl(新行)标志。在
secho
nl
在您的特定用例中,它看起来像
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...")
来自click文档中的echo method
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
因此,组合时,您应该有如下内容
为了得到你想要的东西。在
您可以使用内置的
secho
命令和nl
(新行)标志。在在您的特定用例中,它看起来像
这将为您提供所需的输出
将
click.echo
与click.style
一起使用来自
click
文档中的echo method来自^{} 文档
因此,组合时,您应该有如下内容
^{pr2}$为了得到你想要的东西。在
相关问题 更多 >
编程相关推荐