There is a library for that in Python named 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. "
Works as below:
>>> 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.
Or change the line length:
>>> 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.
>>>