title: Reading a file in chunks using vi from a remote server using Python (3.4)
body: <p>I am reading a .exp file opened in VI on a remote server using python. While Option 2 works for me, it can't read ~1024 bytes at a time. Is my usage of <em>iterator object</em> incorrect in Option 1? Also, I can't figure out why I am unable to read from the <em>stdout</em> buffer more than 512 byte chunks at a time.</p>
  
  <p><strong>Option 1:</strong></p>
  
  <pre><code>#Output: Can't Read File!
  target = open("out.txt", 'w')
  
  def readFile():
         return (str(stdout.read(512))).splitlines(True)
  
  try:
     stdin, stdout, stderr = ssh.exec_command('vi &lt;path\filename.exp&gt;')
     for line in iter(readFile,''):
        target.write(line)
     stdin, stdout, stderr=ssh.exec_command(':q!')
  except:
     print("Can't Read File!") 
  </code></pre>
  
  <p><strong>Option 2:</strong> </p>
  
  <pre><code>#works, but hangs when using stdout.read(1024)
  try:
      stdin, stdout, stderr = ssh.exec_command('vi &lt;path\filename.exp&gt;')
      to_string = (str(stdout.read(512))).splitlines(True)
      for line in to_string:
          target.write(line)
      stdin, stdout, stderr=ssh.exec_command(':q!')
  except:
      print("Can't Read File!")
  </code></pre>