it' not unusual to see program written for the command line with structure somewhat like the following trivial examplefrom my_functions import def (xy)return ( ydef main() result if __name__ ='__main__'main(do you see what might be wrong with this program if we were to run it in ipythonafter it' donenone of the results or objects defined in the main function willl be accessible in the ipython shell better way is to have whatever code is in main execute directly in the module' global namespace (or in the if __name__ ='__main__'blockif you want the module to also be importablethat waywhen you %run the codeyou'll be able to look at all of the variables defined in main it' less meaningful in this simple examplebut in this book we'll be looking at some complex data analysis problems involving large data sets that you will want to be able to play with in ipython flat is better than nested deeply nested code makes me think about the many layers of an onion when testing or debugging functionhow many layers of the onion must you peel back in order to reach the code of interestthe idea that "flat is better than nestedis part of the zen of pythonand it applies generally to developing code for interactive use as well making functions and classes as decoupled and modular as possible makes them easier to test (if you are writing unit tests)debugand use interactively overcome fear of longer files if you come from java (or another such languagebackgroundyou may have been told to keep files short in many languagesthis is sound advicelong length is usually bad "code smell"indicating refactoring or reorganization may be necessary howeverwhile developing code using ipythonworking with smallbut interconnected files (undersay lines eachis likely to cause you more headache in general than single large file or two or three longer files fewer files means fewer modules to reload and less jumping between files while editingtoo have found maintaining larger moduleseach with high internal cohesionto be much more useful and pythonic after iterating toward solutionit sometimes will make sense to refactor larger files into smaller ones tips for productive code development using ipython www it-ebooks info