Get terminal size in perl and python

Skip Montanaro skip at mojam.com
Thu Mar 8 17:42:57 EST 2001


    Egbert> My perl correspondent uses:
    Egbert>     use Term::ReadKey;
    Egbert>     ($cols,$lines)=GetTerminalSize()
    Egbert> What is the python equivalent ?
    Egbert> If I don't come up with one, python looses ten points.

Looks like this will work.  (I've never used curses, so there may be a more
appropriate way to do it.)

    import curses
    stdscr = curses.initscr()
    rows, cols = stdscr.getmaxyx()

For more details, check out the online docs:

    http://www.python.org/doc/current/lib/module-curses.html
    http://www.python.org/doc/howto/curses/curses.html

-- 
Skip Montanaro (skip at mojam.com)
Support Mojam & Musi-Cal: http://www.musi-cal.com/sponsor.shtml
(847)971-7098




More information about the Python-list mailing list