Can you make Counter not write-out “Counter”?

后端 未结 4 1746
渐次进展
渐次进展 2021-01-15 13:22

So when I print the Counter (from collections import Counter) to a file I always get this the literal Counter ({\'Foo\': 12})

Is there anyw

4条回答
  •  情歌与酒
    2021-01-15 13:27

    You could change the __str__ method of the counter class by going into the source code for the collections module, but I wouldn't suggest that as that permanently modifies it. Maybe just changing what you print would be more beneficial?

提交回复
热议问题