def get_path_to_toplevel_modules(filename):
 curr_dir = os.path.dirname(os.path.abspath(filename))
 pattern = '__init__.py'
 try:
  for i in range(10):
   files = set(os.listdir(curr_dir))
   if (pattern in files):
    curr_dir = os.path.dirname(curr_dir)
   else:
    return curr_dir
 except IOError:
  pass
 return None

def get_path_to_toplevel_modules ( filename ) : curr_dir = os . path . dirname ( os . path . abspath ( filename ) ) pattern = '__init__.py' try : for i in range ( 10 ) : files = set ( os . listdir ( curr_dir ) ) if ( pattern in files ) : curr_dir = os . path . dirname ( curr_dir ) else : return curr_dir except IOError : pass return None
return the path to top-level directory that contains python modules .