10 examples of 'python module list' in Python

Every line of 'python module list' 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
48def module_list(path):
49 """
50 Return the list containing the names of the modules available in the given
51 folder.
52 """
53 # sys.path has the cwd as an empty string, but isdir/listdir need it as '.'
54 if path == '':
55 path = '.'
56
57 # A few local constants to be used in loops below
58 pjoin = os.path.join
59
60 if os.path.isdir(path):
61 # Build a list of all files in the directory and all files
62 # in its subdirectories. For performance reasons, do not
63 # recurse more than one level into subdirectories.
64 files = []
65 for root, dirs, nondirs in os.walk(path):
66 subdir = root[len(path)+1:]
67 if subdir:
68 files.extend(pjoin(subdir, f) for f in nondirs)
69 dirs[:] = [] # Do not recurse into additional subdirectories.
70 else:
71 files.extend(nondirs)
72
73 else:
74 try:
75 files = list(zipimporter(path)._files.keys())
76 except:
77 files = []
78
79 # Build a list of modules which match the import_re regex.
80 modules = []
81 for f in files:
82 m = import_re.match(f)
83 if m:
84 modules.append(m.group('name'))
85 return list(set(modules))
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

773def _modules_to_main(modList):
774 """Force every module in modList to be placed into main"""
775 if not modList:
776 return
777
778 main = sys.modules['__main__']
779 for modname in modList:
780 if type(modname) is str:
781 try:
782 mod = __import__(modname)
783 except Exception as e:
784 sys.stderr.write(
785 'warning: could not import %s\n. '
786 'Your function may unexpectedly error due to this import failing;'
787 'A version mismatch is likely. Specific error was:\n' %
788 modname)
789 print_exec(sys.stderr)
790 else:
791 setattr(main, mod.__name__, mod)
12def find_modules():
13 res = list()
14 for entry in sorted(os.listdir(os.getcwd())):
15 init_py = os.path.join(entry, "__init__.py")
16 if os.path.exists(init_py):
17 res.append(entry)
18 if entry.endswith(".py"):
19 res.append(entry)
20 res.remove("tasks.py")
21 return res
94def test( self, filelist ):
95 """
96 Testet ob alle gefunden Dateien auch als Modul
97 importiert werden können
98 """
99 modulelist = []
100 for filename in filelist:
101 try:
102 imp.find_module( filename )
103 except:
104 continue
105 modulelist.append( filename )
106 return modulelist
55def get_mod_list(mod, name):
56 if hasattr(mod, name):
57 mod_list = getattr(mod, name)
58 if not isinstance(mod_list, list):
59 mod_list = [mod_list]
60 return mod_list
61 else:
62 return []
55def get_modules(package_name, module_names):
56 """ List of module objects from the package, keeping the name order. """
57 def get_module(name):
58 return __import__(".".join([package_name, name]), fromlist=[package_name])
59 return [get_module(name) for name in module_names]
30def ls(self):
31 """ Show list of installed extensions. """
32 for n,m in self._active():
33 print '%-20s %s' % (n,m.__file__.replace('\\','/'))
92def moduleslist(this, options, items):
93 result = [u'<ul class="modulesList">']
94 for (name, link) in items:
95 result.append(u'<li>')
96 result.append(u'<a name="//apple_ref/cpp/Module/%s" class="dashAnchor"></a>'%name)
97 result.append(u'<a href="%s">%s</a>'%(link, name))
98 result.append(u'</li>')
99 result.append(u'</ul>')
100 return result
18def get_package_mods(mods,mod_list,prefix='',path=None,level=0):
19 for m in mod_list:
20 try:
21 fp, pathname, description = imp.find_module(m,path)
22 mod = __import__(prefix+m)
23 ##mod = imp.load_module(m, fp, pathname, description)
24 except:
25 import traceback
26 print prefix,m,path
27 print traceback.format_exception(*sys.exc_info())
28 #traceback.print_exception(*sys.exc_info())
29 print 'ERROR: skipping',prefix+m
30 continue
31 try:
32 chpath=mod.__path__
33 except:
34 chpath=None
35 fullname=prefix+m
36 mods[fullname]=None
37 chmods=pkgutil.iter_modules([pathname])
38 mlist=[n[1] for n in chmods if not n[1].startswith('_') and not n[1].startswith('test') and not n[1].startswith('try')]
39 get_package_mods(mods,mlist,fullname+'.',chpath,level+1)
95def getModules(self):
96 if not self._modules is None:
97 return self._modules
98
99 self._modules = []
100 for file in os.listdir(self.modulesDir):
101 filePath = os.path.join(self.modulesDir, file)
102 if not file == '__init__.py' and os.path.isfile(filePath) and os.path.splitext(file)[1] == '.py':
103 moduleName = os.path.splitext(file)[0]
104 module = import_module('gitdh.modules.' + moduleName)
105 self._modules.append(module)
106 return self._modules

Related snippets