title: How to automatically insert spaces to make empty lines in Python files indent?
body: <p>I recently encountered the common <a href="https://stackoverflow.com/questions/1016814">"unexpected indent"</a> problem when trying to evaluate python code by copying them from PyDev and Emacs into a python interpreter.</p>
  
  <p>After trying to fix tab/spaces and some searches, I found the cause in <a href="https://stackoverflow.com/a/41704476/683218">this answer</a>: </p>
  
  <blockquote>
    <p>This error can also occur when pasting something into the Python
    interpreter (terminal/console).</p>
    
    <p>Note that the interpreter interprets an empty line as the end of an
    expression, so if you paste in something like</p>
  </blockquote>
  
  <pre><code>def my_function():
      x = 3
  
      y = 7
  </code></pre>
  
  <blockquote>
    <p>the interpreter will interpret the empty line before y = 7 as the end
    of the expression ...</p>
  </blockquote>
  
  <p>, which is exactly the case in my situation. And there is also a comment to the answer which points out a solution:</p>
  
  <blockquote>
    <p>key being that blank lines within the function definition are fine,
    but they still must have the initial whitespace since Python
    interprets any blank line as the end of the function</p>
  </blockquote>
  
  <p>But the solution is impractical as I have many empty lines that are problematic for the interpreter. My question is:</p>
  
  <p><em>Is there a method/tool to <strong>automatically</strong> insert the right number of initial whitespaces to empty lines so that I can copy-and-paste my code from an editor to an interpreter?</em></p>