Get path for every file python loads when importing modules -


i'm trying make directory containing modules python script depends on. rather manually tracking down files, automatically find these files python imports them. this, i've added module finder sys.meta_path:

import sys, imp class importprint(object):     def find_module(self, name, path=none):         toks = name.split(".")         pre, loc = ".".join(toks[:-1]), toks[-1]         try:              module_info = imp.find_module(loc, path)         except importerror:             module_info = imp.find_module(loc)         if module_info[0]: module_info[0].close         print "a", name, module_info[1]         return none sys.meta_path = [importprint()]  import mymod1, mymod2, etc.. 

this works, __init__.py files not found way. there better way find them, or should hackily add them whenever file found directory? method miss other files.

according documentation sys.meta_path, find_module method called path argument set path of package if one. why not use os.path.join(path, '__init__.py') when path exists?


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -