title: Write image text to a new text file?
body: <p>I am using tesseract for OCR. I am on ubuntu 18.04.</p>
  
  <p>I have this program which extracts the texts from an image and print it. I want that program to create a new text file and paste the extracted content on to the new text file, but I am only able to do these</p>
  
  <ul>
  <li>copy the content to clipboard</li>
  <li>open new texteditor(geditor) file
  I don't know how to paste the copied content</li>
  </ul>
  
  <p>Here is my program which extracts the text from image</p>
  
  <pre><code>from pytesseract import image_to_string 
  from PIL import Image
  print image_to_string(Image.open('sample.jpg'))
  </code></pre>
  
  <p>Here is the program which copies the text to clipboard,</p>
  
  <pre><code>import os
  def addToClipBoard(text):
      command = 'echo ' + text.strip() + '| clip'
      os.system(command)
  </code></pre>
  
  <p>This program will open the geditor and create  a new text file</p>
  
  <pre><code>import subprocess
  proc = subprocess.Popen(['gedit', 'file.txt'])
  </code></pre>
  
  <p>Any help would be appreciated.</p>