有該庫在Python命名textwrap
:
>>> import textwrap
>>> strs = "Is there a way to write a long string of words to a text file in python3 so that the string can be written over several lines? This is what I have tried so far. Is there a way to write a long string of words to a text file in python3 so that the string can be written over several lines? This is what I have tried so far. "
作如下處理:
>>> print (textwrap.fill(strs, 20))
Is there a way to
write a long string
of words to a text
file in python3 so
that the string can
be written over
several lines? This
is what I have tried
so far. Is there a
way to write a long
string of words to a
text file in python3
so that the string
can be written over
several lines? This
is what I have tried
so far.
或改變線路長度:
>>> print (textwrap.fill(strs, 40))
Is there a way to write a long string of
words to a text file in python3 so that
the string can be written over several
lines? This is what I have tried so far.
Is there a way to write a long string of
words to a text file in python3 so that
the string can be written over several
lines? This is what I have tried so far.
>>>
你的title卻沒有真正符合你的描述 – karina
我認爲這就是你要找的東西http://stackoverflow.com/questions/10660435/pythonic-way-to-create-a-long-multi-line-string – karina
你是什麼意思「字符串可以寫成多行」? – EbraHim