python自动换行符,python单击帮助格式化换行符
I am seeing that a newline is not being preserved in my EPILOG? I want to know why if I see that newline remains only when a line has 74 characters?
# http://click.pocoo.org/5/commands/
import click, sys
def main_caller(*args, **kwargs):
print('act on arguments', args, kwargs)
EPILOG = '''
# oneline
# twoline
\n
# oneline with 74char x
# twoline with 74char x
'''
@click.group(help='wwwwwwwwww', epilog=EPILOG, invoke_without_command=True, chain=True)
@click.argument('start_or_stop')
@click.option('-v', '--verbose', default=False, help='Print Verbose messages')
@click.option('-l', '--logfile', help='Path to logfile to store log messages')
@click.option('-a', '--action', multiple=True, type=click.Choice(['act1', 'act2', 'act3']), default=['act1', 'act2'])
def cli(*args, **kwargs):
'''foo bar'''
pass
@cli.command()
@click.option('--debug/--no-debug', default=False)
def cmd1(*args, **kwargs):
print('cmd1', args, kwargs)
return 'cmd11111'
@cli.command()
@click.option('-x', '--xxx', default='x')
def cmd2(*args, **kwargs):
print('cmd2', args, kwargs)
return 'cmd22222'
@cli.resultcallback()
def process_pipeline(*args, **kwargs):
print('process', args, kwargs)
print('args', sys.argv[1:])
if __name__ == '__main__':
cli()
Output is:
/click_sandbox.py --help
2017/02/24 19:31:43 Platform overridden to 'RHEL5_64'
Usage: click_sandbox.py [OPTIONS] START_OR_STOP COMMAND1 [ARGS]... [COMMAND2
[ARGS]...]...
wwwwwwwwww
Options:
-v, --verbose TEXT Print Verbose messages
-l, --logfile TEXT Path to logfile to store log messages
-a, --action [act1|act2|act3]
--help Show this message and exit.
Commands:
cmd1
cmd2
# oneline # twoline
# oneline with 74char x
# twoline with 74char x
解决方案
Your newlines are not being preserved because the epilog writer does word wrapping. This can be solved with a subclass to click.Group, by creating a format_epilog() which does not do word wrapping:
class SpecialEpilog(click.Group):
def format_epilog(self, ctx, formatter):
if self.epilog:
formatter.write_paragraph()
for line in self.epilog.split('\n'):
formatter.write_text(line)
# Tell click to use our epilog formatter
@click.group(cls=SpecialEpilog,
help='wwwwwwwwww', epilog=EPILOG, invoke_without_command=True, chain=True)
....
python自动换行符,python单击帮助格式化换行符相关推荐
- python中的换行符是什么_python的换行符是什么?_后端开发
python换行符是什么? python换行符是"\n". Windows换行符是'\r\n', Unix/Linux的换行符为'\n', Mac的换行符为'\r', 在pytho ...
- python换行符怎么键入_python的换行符是什么?
python换行符是什么? python换行符是"\n". Windows换行符是'\r\n', Unix/Linux的换行符为'\n', Mac的换行符为'\r', 在pytho ...
- linux中excel的换行符,Excel skill: 如何替换换行符,以及如何把一格转换成多行/多列...
增加一辅助列,用替换函数替换掉软回车. 比如A列是数据,从A1开始,则插入B列,B1输入公式 =REPLACE(A1,FIND(CHAR(10),A1),1,"") 再用填充柄向下 ...
- Linux和windows中的换行符差异问题 LINUX的换行符在Windows记事本打开不换行或出现黑点
http://hi.baidu.com/mayongl7/blog/item/06e61af7c719053a730eec4d.html LINUX的换行符在Windows记事本打开不换行或出现黑点 ...
- linux open换行windows,python中遇到的Windows系统中换行符的一个坑
在项目hex2bin( https://github.com/Root-lee/hex2bin ) 中,需要实现将一个txt文本中的十六进制码转换成相应的ascii码符号并写入一个.dat文件中,以用 ...
- python换行符 n怎么用_Python换行符问题:\r\n还是\n?
章硕,js & python 夏一一.乔3少 赞同 这不是python的问题,windows的换行是\r\n,unix的是\n,mac的是\r. 这是一个很经典的问题.因为不同系统下默认的换行 ...
- python获取文件换行符_python – 读取文件没有换行符
您可以使用str.splitlines读取整个文件和拆分线: temp = file.read().splitlines() 或者你可以手工剥离换行: temp = [line[:-1] for li ...
- word2016能识别linux换行符,word文章中的换行符如何批量替换为回车符
word文件中有换行符很正常,但是想要将换行符全部替换为回车符,该怎么替换?以下是学习啦小编为您带来的关于word文章中的换行符批量替换为回车符,希望对您有所帮助. word文章中的换行符批量替换为回 ...
- php 将换行符替换,PHP替换回车换行符的三种方法
小小的回车换行,在不同的平台有着不同的实现. 为什么要这样,世界是多样的! 推荐学习:PHP视频教程 本来,在Unix / Linux世界换行用\n, Windows为了体现不同,就用\r\n, 更有 ...
最新文章
- 11.typescript-元组
- Linux段式管理与页式管理
- Phpcms之核心目录phpcms
- 光落在你脸上,可爱一如往常
- 朋友圈自动回复评论_微信新版,朋友圈可以表情包回复了!网友:评论区斗起来.jpg...
- mysql 嵌入式 性能_database – 在mySQL中优化嵌入式SELECT查询
- Hadoop框架:HDFS读写机制与API详解
- 函授计算机大专自我鉴定100字,函授大学毕业自我鉴定100字(精选5篇)
- asp.net mvc中的后台验证
- C# 尝试读取或写入受保护的内存。这通常指示其他内存已损坏
- Maven的配置和使用(三)
- jQuery插件实现表格隔行换色且感应鼠标高亮行变色
- linux lammps 安装教程,LAMMPS安装总结
- Vmware虚拟机红帽子Linux联网
- Sublime常用快捷键
- Thinking in java 第21章 并发 wait() 与 notifyAll()
- java 电子栅栏,Java Exchanger栅栏
- 刘世光 计算机图像学,刘世光
- Python爬虫练习-查询lol隐藏分
- 机器学习服务活体检测算法荣获CFCA权威安全认证