title: IOError: [Errno 25] Inappropriate ioctl for device
body: <p>I have the following code to find the width of the console in Linux, which works in both Python 2.7 and Python 3.X:</p>
  <pre><code>def get_default_console_width():
     try:
        from shutil import get_terminal_size
        console_width, rows = shutil.get_terminal_size()
     except Exception:
        import termios, fcntl, struct, sys
        s = struct.pack('hh', 0, 0)
        x = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, s)
        rows, console_width = struct.unpack(&quot;hh&quot;, x)
     return console_width
  </code></pre>
  <p>In my test_something.py file I test some function that calls <em>get_default_console_width()</em> and it gives me this error:</p>
  <pre><code>IOError: [Errno 25] Inappropriate ioctl for device
  </code></pre>
  <p>I know there are some similar posts with the same issue, but I did not find anything that would help in this case.</p>
  <p>Any help is appreciated! Thanks!</p>