title: Get text contents of what has been printed python
body: <p>Lets say I print the following code</p>
  
  <pre><code>print("""
  THE RUSSIAN PEASANT ALGORITHM
  -----------------------------
  times two values x and y together
  
  
  """)
  
  x=int(raw_input("raw_input x: "))
  y=int(raw_input("raw_input y: "))
  
  print("x"+" "*(10)+"y")
  
  while x!=1:
        x=x/2
        y=y*2
  
        print(str(x)+" "*10+str(y))
  </code></pre>
  
  <p>This prints the results of an algorithm, appropiately to the numbers that the user enterred.Now if I wished to get a variable containing all that had been outputted to the python console, how would I go about that?</p>
  
  <p>EDIT: To clarify the reason I want the output if so basically I can clear the screen with "CLS" and reprint everything I've already printed but with the even x values crossed out as you are supposed to do with the russian peasant algorithm.</p>