I want to indent all lines of a multi-line string except the first, without wrapping the text.
For example, I want to turn:
A very very very very very very very very very very very very very very very very
long mutiline
string
into:
A very very very very very very very very very very very very very very very very
long multiline
string
I have tried
textwrap.fill(string, width=999999999999, subsequent_indent=' ',)
But this still puts all of the text on one line. Thoughts?
Highlight/ select the lines you want indented, then press TAB as often as needed until they reach the proper indent level. You can remove spaces with SHIFT TAB . You can also use CTRL+ALT+I to auto-indent the selection.
If you want to remove indentation that is common to the whole multiline string, use textwrap. dedent().
wrap(text, width=70, **kwargs): This function wraps the input paragraph such that each line in the paragraph is at most width characters long. The wrap method returns a list of output lines. The returned list is empty if the wrapped output has no content.
You just need to replace the newline character '\n'
with a new line character plus the white spaces '\n '
and save it to a variable (since replace
won't change your original string, but return a new one with the replacements).
string = string.replace('\n', '\n ')
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