destinationsby defining an object with write method that does the required routing you'll see an example of this trick when we study classes in part vi of this bookbut abstractlyit looks like thisclass filefakerdef write(selfstring)do something with printed text in string import sys sys stdout filefaker(print(someobjectssends to class write method this works because print is what we will call in the next part of this book polymorphic operation--it doesn' care what sys stdout isonly that it has method ( interfacecalled write this redirection to objects is made even simpler with the file keyword argument in and the >extended form of print in xbecause we don' need to reset sys stdout explicitly--normal prints will still be routed to the stdout streammyobj filefaker( xredirect to object for one print print(someobjectsfile=myobjdoes not reset sys stdout myobj filefaker(print >myobjsomeobjects xsame effect does not reset sys stdout python' ' built-in input function (named raw_input in xreads from the sys stdin fileso you can intercept read requests in similar wayusing classes that implement file-like read methods instead see the input and while loop example in for more background on this function notice that because printed text goes to the stdout streamit' also the way to print html reply pages in cgi scripts used on the weband enables you to redirect python script input and output at the operating system' shell command line as usualpython script py outputfile python script py filterprogram python' print operation redirection tools are essentially pure-python alternatives to these shell syntax forms see other resources for more on cgi scripts and shell syntax summary in this we began our in-depth look at python statements by exploring assignmentsexpressionsand print operations although these are generally simple to usethey have some alternative forms thatwhile optionalare often convenient in practice --augmented assignment statements and the redirection form of print operationsfor exampleallow us to avoid some manual coding work along the waywe also studied the syntax of variable namesstream redirection techniquesand variety of common mistakes to avoidsuch as assigning the result of an append method call back to variable summary