title: How to differentiate /dev/tty with stdin, stdout, stderr?
body: <p>I try this with Python3:</p>
  
  <pre><code>import os
  fd = os.open('/dev/tty', os.O_RDWR|os.O_NOCTTY)
  print(fd)
  </code></pre>
  
  <p>It always prints 3 in Linux. Is /dev/tty file descriptor always 3?</p>
  
  <p>I want to differentiate /dev/tty with stdin,stdout,stderr. My initial attempt is to check the file descriptor since stdin,stdout,stderr return 0, 1, or 2.</p>
  
  <p>The reason I am asking this is because to write to /dev/tty in Python, I have to use bytes not string while with stdin,stderr,stdout, I have to use string.</p>
  
  <p>So my second attempt is:</p>
  
  <pre><code>try:
      if file.isatty() and file not in [sys.stdout,sys.stdin,sys.stderr]:
          use_bytes = True
      else:
          use_bytes = False
  except AttributeError:
      use_bytes = False
  </code></pre>
  
  <p>Is there any better way to do this?</p>