to read their output file objects also have write methods for sending strings to the associated file file-related topics are covered in depth in but making an output file and reading it back is easy in pythonfile open('spam txt'' 'file write(('spam '\ ' file close(create file spam txt write textreturns #characters written file open('spam txt'text file read(text 'spamspamspamspamspam\nor open('spam txt'read(read into string using programs in two ways also by way of reviewthe last few lines in the more py file in example - introduce one of the first big concepts in shell tool programming they instrument the file to be used in either of two ways--as script or as library recall that every python module has built-in __name__ variable that python sets to the __main__ string only when the file is run as programnot when it' imported as library because of thatthe more function in this file is executed automatically by the last line in the file when this script is run as top-level programbut not when it is imported elsewhere this simple trick turns out to be one key to writing reusable script codeby coding program logic as functions rather than as top-level codeyou can also import and reuse it in other scripts the upshot is that we can run more py by itself or import and call its more function elsewhere when running the file as top-level programwe list on the command line the name of file to be read and pagedas 'll describe in more depth in the next words typed in the command that is used to start program show up in the built-in sys argv list in python for examplehere is the script file in actionpaging itself (be sure to type this command line in your pp \system directoryor it won' find the input filemore on command lines later) :\pp \systempython more py more py ""split and interactively page string or file of text ""def more(textnumlines= )lines text splitlines(like split('\ 'but no 'at end while lineschunk lines[:numlineslines lines[numlines:for line in chunkprint(linemore? if lines and input('more?'not in [' '' ']break system tools