Get terminal size in perl and python

Skip Montanaro skip at
Thu Mar 8 23:42:57 CET 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:

Skip Montanaro (skip at
Support Mojam & Musi-Cal:

More information about the Python-list mailing list