【发布时间】:2018-09-01 20:05:13
【问题描述】:
我想为 CommentedSeq 对象分配新值以保留其流样式。但是,这样的操作会导致TypeError: '<' not supported between instances of 'slice' and 'int'。
这是否意味着 CommentedSeq 不支持就地分配,这是 Python 列表的最基本功能?
from ruamel.yaml import YAML
y = YAML()
x = y.seq([1, 2])
x.fa.set_flow_style()
x[:] = [3, 4]
451 # type: (Any, Any) -> None
452 # try to preserve the scalarstring type if setting an existing key to a new value
--> 453 if idx < len(self):
454 if isinstance(value, string_types) and \
455 not isinstance(value, ScalarString) and \
TypeError: '<' not supported between instances of 'slice' and 'int'
【问题讨论】:
标签: python yaml ruamel.yaml