遇到了namedtuple
打印问题:
Info = namedtuple('Info', ['type', 'value', 'x', 'y'])
这样可以使值对齐,并在它们之间留出空白(padding),例如:
Info( type='AAA', value=80000, x=16.4, y=164.2 )
Info( type='A', value=78, x=1.5, y=11.3 )
Info( type='ABBCD', value=554, x=11.7, y=10.1 )
Info( type='AFFG', value=1263, x=121.3, y=12.8 )
理想情况下,没有逗号。 我尝试过使用
pprint
和使用_asdict
打印,但没有成功,如这里所建议的那样。对于命名元组,format
也是同样的情况。
有什么想法或示例代码吗?