Indent On New Lines In Console
<p>I have a large block of text. It has line breaks in it, but since the lines are still to long even with the line-breaks, it wraps to the next line. Since all of the other script functions have all lines indented one space, I would like this to match it. I understand that if I print just one line, I can just insert a space, and if I want to indent after a linebreak that fit in one line, I can just insert <code>\n</code> with a space after it.</p>

<p>How would I make every line in a block of text indent? e.g:</p>

<p><code>text = """This is a block of text. It keeps going on
           and on and on. It has some line breaks \n
           but mostly just keeps going on without
           breaks. The lines are sometimes too long,
           so they wrap to the next line, but they 
           don't indent. I need to fix this"""</code></p>

<p>that would print as:</p>

<pre><code>&gt;&gt;&gt; print(text) 
  This is a block of text. It keeps going on
  and on and on. It has some line breaks

  but mostly just keeps going on without
  breaks. The lines are sometimes too long,
  so they wrap to the next line, but they 
  don't indent. I need to fix this
</code></pre>

<p>You said that join, split are failing to import. Try the following:</p>

<pre><code>import re, textwrap

def myformatting(t):
    t=re.sub('\s+',' ',t); t=re.sub('^\s+','',t); t=re.sub('\s+$','',t)
    t=textwrap.wrap(t,width=40,initial_indent=' '*4,subsequent_indent=' '*8)
    s=""
    for i in (t): s=s+i+"\n"
    s=re.sub('\s+$','',s)
    return(s)

text = """\t\tThis is a block of text. It keeps going on
            and on and on. It has    some line breaks \n
            but mostly just keeps going on without
            breaks. The lines are sometimes too long,
            so they wrap to the next line, but they 
            don't indent. I need to fix this"""

text=myformatting(text)
print text
</code></pre>

python console auto-indent