我正在尝试使用鲁阿迈尔.亚马尔. 我需要显式引用一些字符串,以便将它们传递给ruamel.yaml.scalarstring公司.DoubleQuotedScalarString,它在输出中将它们用双引号括起来。但是,覆盖多行的字符串在输出中包含\字符。如何防止这种情况?你知道吗
在将字符串传递给ruamel.yaml.scalarstring公司.DoubleQuotedScalarString并将其替换为“”,但这不起作用。我认为这些字符是在转储时添加的。你知道吗
S = ruamel.yaml.scalarstring.DoubleQuotedScalarString
string = "The Parkinson's Disease Sleep Scale-Validation (PDSS-2) is a scale used to characterise and quantify the various aspects of nocturnal sleep problems in Parkinson's disease (PD). The PDSS-2 is a revised version of the Parkinson's Disease Sleep Scale (PDSS)."
st = S(string)
data = {'key': st}
f = open('./yam.yaml', 'w')
yaml= YAML()
yaml.default_flow_style = False
yaml.indent(offset = 2, sequence = 4, mapping = 2)
yaml.dump(data, f)
期望值:
key: "The Parkinson's Disease Sleep Scale-Validation (PDSS-2) is a scale used to characterise and quantify the various aspects of nocturnal sleep problems in Parkinson's disease (PD). The PDSS-2 is a revised version of the Parkinson's Disease Sleep Scale (PDSS)."
实际值:
key: "The Parkinson's Disease Sleep Scale-Validation (PDSS-2) is a scale used to characterise\
\ and quantify the various aspects of nocturnal sleep problems in Parkinson's disease\
\ (PD). The PDSS-2 is a revised version of the Parkinson's Disease Sleep Scale (PDSS)."
您看到的是由换行引起的,它试图将输出中的行长度限制为默认的80个字符。你知道吗
如果您可以使用更广泛的输出,那么只需将
yaml.width
设置为更大的值:它给出:
相关问题 更多 >
编程相关推荐