file are run at import time to create functions and assign attributes within the module to those functions the functions can then be called later in the program by the file' importers because this last import step actually runs the file' codeif any top-level code in module file does real workyou'll see its results at import time for exampletop-level print statements in module show output when the file is imported function def statements simply define objects for later use as you can seeimport operations involve quite bit of work--they search for filespossibly run compilerand run python code because of thisany given module is imported only once per process by default future imports skip all three import steps and reuse the already loaded module in memory if you need to import file again after it has already been loaded (for exampleto support dynamic end-user customizations)you have to force the issue with an imp reload call-- tool we'll meet in the next byte code files__pycache__ in python as mentioned brieflythe way that python stores files to retain the byte code that results from compiling your source has changed in python and later first of allif python cannot write file to save this on your computer for any reasonyour program still runs fine--python simply creates and uses the byte code in memory and discards it on exit to speed startupsthoughit will try to save byte code in file in order to skip the compile step next time around the way it does this varies per python versionin python and earlier (including all of python xbyte code is stored in files in the same directory as the corresponding source filesnormally with the filename extension pyc ( module pycbyte code files are also stamped internally with the version of python that created them (known as "magicfield to developersso python knows to recompile when this differs in the version of python running your program for instanceif you upgrade to new python whose byte code differsall your byte code files will be recompiled automatically due to version number mismatcheven if you haven' changed your source code in python and later byte code is instead stored in files in subdirectory named __pycache__which python creates if neededand which is located in the directory containing the corresponding source files this helps avoid clutter in your source directories by segregating the byte code files in their own directory in additionalthough byte code as described earlierpython keeps already imported modules in the built-in sys modules dictionary so it can keep track of what' been loaded in factif you want to see which modules are loadedyou can import sys and print list(sys modules keys()there' more on other uses for this internal table in modulesthe big picture