我发现了
以下是每个示例的输出样本:
ValueError
和KeyError
之间的不一致性。前者将\n
视为换行符;后者将其视为原始文本。这种行为是否正常/预期?
TeX_dict
是一个字典,用于将字典键的部分转换为TeX格式的字符串,在生成图时使用。 part
是其中之一。以下是part
的两个示例:
a&b
成功拆分并转换为字典中的内容。a,b&c
则未能成功拆分。
ValueError
时,\n
换行符会生成新行。但当我引发KeyError
时,它们不会。geo_split = lambda thing: '\&'.join([
TeX_dict[x]
for x in thing.split('&')
])
try:
TeX = geo_split(part)
except KeyError:
msg = ("You have programmed limited functionality for "
"geometric mean keys. They can only handle species "
"that are hard coded into "
"``pccv.TeX_labels.axis_labels``.\n\n" #
"The following part failed: {}\n"
).format(part)
raise ValueError(msg) # If this is KeyError, the new lines don't print.
以下是每个示例的输出样本:
ValueError: You have programmed limited functionality for geometric mean keys.
They can only handle species that are hard coded into
``pccv.TeX_labels.axis_labels``.
KeyError: 'You have programmed limited functionality for geometric mean keys.
They can only handle species that are hard coded into
``pccv.TeX_labels.axis_labels``.\n\nThe following part failed: a,p1&p2\n'