title: How to open <del>named pipe</del>character device special file for reading and writing in Python
body: <p>I have a service running on a Linux box that creates a <del>named pipe</del> character device-special file, and I want to write a Python3 program that communicates with the service by writing text commands and reading text replies from the <del>pipe</del> device.  I don't have source code for the service.</p>
  
  <p>I can use <code>os.open(named_pipe_pathname, os.O_RDWR)</code>, and I can use <code>os.read(...)</code> and <code>os.write(...)</code> to read and write it, but that's a pain because I have to write my own code to convert between bytes and strings, I have to write my own <code>readline(...)</code> function, etc.</p>
  
  <p>I would much rather use a Python3 <code>io</code> object to read and write the <del>pipe</del> device, but every way I can think to create one returns the same error:</p>
  
  <pre><code>io.UnsupportedOperation: File or stream is not seekable.
  </code></pre>
  
  <p>For example, I get that message if I try <code>open(pathname, "r+")</code>, and I get that same message if I try <code>fd=os.open(...)</code> followed by <code>os.fdopen(fd, "r+", ...)</code>.</p>
  
  <p>Q: What is the preferred way for a Python3 program to write and read text to and from a <del>named pipe</del> character device?</p>
  
  <hr>
  
  <p>Edit:</p>
  
  <p>Oops! I assumed that I was dealing with a named pipe because documentation for the service describes it as a "pipe" and, because it doesn't appear in the file system until the user-mode service runs.  But, the Linux <code>file</code> utility says it is in fact, a character device special file.</p>