I'm using Python to gather data from a Web service. The data itself is a list that will presented to users. I've managed it that it's printed out like:
( 1) Example of strings
( 2) Example 4
( 3) Another Example
( 4) Another Example 2
I'm using rjust (2) for the numbers. However, if the lines are very long, the printing will be like. The breaking width is the length of terminal (rxvt, gnome-terminal):
( 1) Example of a very very very very long string and
that doesn't look fine
( 2) Example of indented long line that is very very
long, example line
( 3) Another Example
( 4) Another Example of a very very long string and
whatever here is
But what I've want is a print out like:
( 1) Example of a very very very very long string and
that doesn't look fine
( 2) Example of indented long line that is very very
long, example line
( 3) Another Example
( 4) Another Example of a very very long string and
whatever here is
Is there any ideas how to print the lines like above without breaking up the lines manually?
Use the textwrap module: http://docs.python.org/library/textwrap.html
textwrap.fill(text, initial_indent='', subsequent_indent=' ')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With