import os print os.name from os import name print name # File calc.py # Function defined in module def average(list): return float(sum(list)) / len(list) # Imports calc module import calc l = [23, 54, 31, 77, 12, 34] # Calls the function defined in calc print calc.average(l) if __name__ == "__main__": # Code here will only be run # if it is the main module # and not when it is imported by another program pass """ modutils => utility routines for modules """ import os.path import sys import glob def find(txt): """find modules with name containing the parameter """ resp = [] for path in sys.path: mods = glob.glob('%s/*.py' % path) for mod in mods: if txt in os.path.basename(mod): resp.append(mod) return resp from os.path import getsize, getmtime from time import localtime, asctime import modutils mods = modutils.find('xml') for mod in mods: tm = asctime(localtime(getmtime(mod))) kb = getsize(mod) / 1024 print '%s: (%d kbytes, %s)' % (mod, kb, tm)