use windows console tools msvcrt putch( '\ 'getch(does not echo key return key elseassert false'platform not supported#linux?open('/dev/tty'readline()[:- def more(textnumlines= )""page multiline string to stdout ""lines text splitlines(while lineschunk lines[:numlineslines lines[numlines:for line in chunkprint(lineif lines and getreply(not in [ ' ' ' ']break if __name__ ='__main__'if len(sys argv= more(sys stdin read()elsemore(open(sys argv[ ]read()when runnot when imported if no command-line arguments page stdinno inputs else page filename argument most of the new code in this version shows up in its getreply function the file' isatty method tells us whether stdin is connected to the consoleif it iswe simply read replies on stdin as before of coursewe have to add such extra logic only to scripts that intend to interact with console users and take input on stdin in gui applicationfor examplewe could instead pop up dialogsbind keyboard-press events to run callbacksand so on (we'll meet guis in armed with the reusable getreply functionthoughwe can safely run our moreplus utility in variety of ways as beforewe can import and call this module' function directlypassing in whatever string we wish to pagefrom moreplus import more more(open('addersmall py'read()import sys print(sum(int(linefor line in sys stdin)also as beforewhen run with command-line argumentthis script interactively pages through the named file' textc:\pp \system\streamspython moreplus py addersmall py import sys print(sum(int(linefor line in sys stdin) :\pp \system\streamspython moreplus py moreplus py ""split and interactively page stringfileor stream of text to stdoutwhen run as scriptpage stdin or file whose name is passed on cmdlineif input is stdincan' use it for user reply--use platform-specific tools or gui""standard streams