Every line of 'python print module path' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
154 def find_module(module_name, path=None): 155 """ Returns the filename for the specified module. """ 156 157 components = module_name.split('.') 158 159 try: 160 # Look up the first component of the module name (of course it could be 161 # the *only* component). 162 f, filename, description = imp.find_module(components[0], path) 163 164 # If the module is in a package then go down each level in the package 165 # hierarchy in turn. 166 if len(components) > 0: 167 for component in components[1:]: 168 f,filename,description = imp.find_module(component, [filename]) 169 170 except ImportError: 171 filename = None 172 173 return filename
267 def get_module_path(modname): 268 """Return module *modname* base path""" 269 module = sys.modules.get(modname, __import__(modname)) 270 return osp.abspath(osp.dirname(module.__file__))
249 def get_module_path(fpath): 250 """Given a module filename, return its full Python name including 251 enclosing packages. (based on existence of ``__init__.py`` files) 252 """ 253 if basename(fpath).startswith('__init__.'): 254 pnames = [] 255 else: 256 pnames = [splitext(basename(fpath))[0]] 257 path = dirname(abspath(fpath)) 258 while isfile(join(path, '__init__.py')): 259 path, pname = split(path) 260 pnames.append(pname) 261 return '.'.join(pnames[::-1])
25 def module_path(): 26 encoding = sys.getfilesystemencoding() 27 if we_are_frozen(): 28 try: 29 filename = unicode(sys.executable, encoding) 30 except TypeError: 31 filename = sys.executable 32 else: 33 try: 34 filename = unicode(__file__, encoding) 35 except TypeError: 36 filename = __file__ 37 return os.path.dirname(filename)