title: How to clear console line using `print` function
body: <h1>Premise</h1>
  
  <p>I'm trying to basically clear the console line, but not the entire console window without using whitespace, so that I don't have extra characters from what was last printed. For example:</p>
  
  <pre><code># This causes characters from the last thing printed:
  print("I don't know you.", end="\r")
  print("Hello Jim!", end="\r")
  
  # Yields the following (without the quotations) --&gt;
  # "Hello Jim!ow you."
  </code></pre>
  
  <p>Now to solve this one can do this:</p>
  
  <pre class="lang-py prettyprint-override"><code>import os
  
  def new_print(message, end):
      """
      Clears console, no matter the size of the previous line 
      without wrapping to a new line
      """
      width_of_console = int(os.popen("stty size", "r").read().split()[1])
      # = 17
  
      print(f"{message :&lt;{width_of_console}}", end=end)
  
  new_print("I don't know you.", end="\r")
  new_print("Hello Jim!", end="\r")
  # Yields the following (without the quotations) --&gt;
  # "Hello Jim!       "
  </code></pre>
  
  <h1>Question</h1>
  
  <p>How do I </p>
  
  <ol>
  <li><em>Just</em> print out <code>"Hello Jim!"</code> and not <code>"Hello Jim!       "</code> (both obviously without quotations)</li>
  <li>Clear that line</li>
  <li>While not clearing the entire console (so that I have the output of other things besides the last line)</li>
  </ol>
  
  <p>Specifically things like this occur in the console when shifting sizes (from say a console width of 17 to 30), which in my case, happens quite often:</p>
  
  <pre><code>Hello Jim!       Hello Jim!   
      Hello Jim!       Hello Jim
  !       Hello Jim!       Hello
   Jim!       Hello Jim!       H
  ello Jim!       Hello Jim!    
  
  </code></pre>
  
  <p>I'm open to an entire new way of doing things, like using <a href="http://urwid.org/" rel="nofollow noreferrer">urwid</a> or something of that nature.</p>