Python:将textwrap转换为列表
我有一个变量:
row='saint george 1739 1799 violin concerti g 029 039 050 symphonie concertante for two violins g 024 bertrand cervera in 024 039 christophe guiot in 024 029 and thibault vieux violin soloists orchestre les archets de paris'
我正在做这个:
textwrap.fill(row,55)
我希望有一个列表 line
,让它的内容是 line[0]='saint george 1739 1799 violin concerti g 029 039 050'
和 line[1]='symphonie concertante for two violins g 024 bertrand'
等等……
请帮我把这个文本转换成一个列表
请注意,textwrap 是通过 \n
来分隔内容的
3 个回答
1
1
textwrap.wrap
会返回一个列表。那为什么不直接用这个呢?
textwrap.fill(text, ...)
相当于 "\n".join(wrap(text, ...))
。这个在文档中有解释。
1
用 textwrap.wrap
替代 textwrap.fill
。