title: Python: How to write to and read from an existing PseudoTerminal (pty/pts)
body: <p>I am attempting to programmatically interact with an existing program that provides an interface via a pseudo terminal (/dev/pts/1)</p>
  
  <p>I have a poor understanding of how this works.  I can currently interact crudely but successfully with:<br>
  <code>echo SomeCommandToSend &gt;&gt; /dev/pts/1</code></p>
  
  <p>And can equally crudely retrieve results with:<br>
  <code>cat /dev/pts/1</code></p>
  
  <p>Question: How can I cleanly and programmatically interact with this pseudo terminal from Python?</p>
  
  <p>I have looked at <a href="https://docs.python.org/2/library/pty.html" rel="nofollow noreferrer" title="docs">these docs</a> but was unable to see how to use that in this case, as I do not want to spawn a new process, just communicate with an existing one.</p>