如何防止YAML在没有换行的情况下转储长行 [英] How to prevent YAML to dump long line without new line
问题描述
只要我的选择超出特定限制,pyyaml就会将其转换为两行.
Whenever my option goes beyond certain limit, pyyaml converts it into two lines.
如何避免这种情况?
例如
在[1]中:x ="-c/home/user/test/test2/test23/tet/2s/test1/stest/longdirectory1/directory2/--optnion12 --verbose"
In [1]: x = "-c /home/user/test/test2/test23/tet/2s/test1/stest/longdirectory1/directory2/ --optnion12 --verbose"
在[2]中:import yaml
在[3]中:print yaml.dump([dict(ATTRIBUTES=[dict(CONFIG=x)])], default_flow_style=False)
犯错
- ATTRIBUTES:
- CONFIG: -c /home/user/test/test2/test23/tet/2s/test1/stest/longdirectory1/directory2/
--optnion12 --verbose
应该什么样
- ATTRIBUTES:
- CONFIG: -c /home/user/test/test2/test23/tet/2s/test1/stest/longdirectory1/directory2/ --optnion12 --verbose
推荐答案
感谢@MathieuMarques建议使用@dump选项和提供的链接,YAML文档不足以找到它.
Thanks @MathieuMarques for suggesting to look @ dump options and link provided, YAML documentation was not good enough to find it out.
无论如何,解决方案是为dump
函数指定width
参数.
Anyways solution is to specify width
parameter for dump
function.
即yaml.dump(data, width=1000)
这篇关于如何防止YAML在没有换行的情况下转储长行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!