Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

14
  • 5
    COLUMNS isn't exported by default in Bash, that's why os.environ["COLUMNS"] doesn't work. Commented Dec 5, 2012 at 17:33
  • 42
    rows, columns = subprocess.check_output(['stty', 'size']).split() is a little shorter, plus subprocess is the future Commented Mar 17, 2015 at 2:00
  • 10
    tput is better than stty, as stty cannot work with PIPE. Commented Jul 14, 2015 at 12:35
  • 6
    rows, columns = subprocess.check_output(['stty', 'size']).decode().split() If you want unicode strings for py2/3 compatibility Commented Aug 2, 2016 at 19:55
  • 3
    Do not use a process (especially from the deprecated os.popen), for this except as a last resort. Commented Sep 6, 2018 at 22:35