enter number>bye this is an artificial exampleof coursebut the techniques illustrated are widely applicable for instanceit' straightforward to add gui interface to program written to interact with command-line user simply intercept standard output with an object such as the output class instance shown earlier and throw the text string up in window similarlystandard input can be reset to an object that fetches text from graphical interface ( popped-up dialog boxbecause classes are plug-and-play compatible with real fileswe can use them in any tool that expects file watch for gui streamredirection module named guistreams in that provides concrete implementation of some of these ideas the io stringio and io bytesio utility classes the prior section' technique of redirecting streams to objects proved so handy that now standard library module automates the task for many use cases (though some use casessuch as guismay still require more custom codethe standard library tool provides an object that maps file object interface to and from in-memory strings for examplefrom io import stringio buff stringio(buff write('spam\ ' buff write('eggs\ ' buff getvalue('spam\neggs\nbuff stringio('ham\nspam\ 'buff readline('ham\nbuff readline('spam\nbuff readline('save written text to string provide input from string as in the prior sectioninstances of stringio objects can be assigned to sys stdin and sys stdout to redirect streams for input and print calls and can be passed to any code that was written to expect real file object againin pythonthe object interfacenot the concrete datatypeis the name of the gamefrom io import stringio import sys buff stringio(temp sys stdout sys stdout buff print( 'spam' script execution context or printfile=buff