解决python 3.6不能相对导入问题

This commit is contained in:
Jing Ling
2020-10-12 21:47:15 +08:00
parent 70a1758597
commit 14f9fe1bfd
+5 -7
View File
@@ -22,9 +22,8 @@ class Collect(object):
for module in modules:
module_path = settings.module_dir.joinpath(module)
for path in module_path.rglob('*.py'):
# Classes to be imported
import_module = ('modules.' + module, path.stem)
self.modules.append(import_module)
import_module = f'modules.{module}.{path.stem}'
self.modules.append([import_module, path.stem])
else:
self.modules = settings.enable_partial_module
@@ -32,8 +31,8 @@ class Collect(object):
"""
Import do function
"""
for package, name in self.modules:
import_object = importlib.import_module('.' + name, package)
for module, name in self.modules:
import_object = importlib.import_module(module)
func = getattr(import_object, 'run')
self.collect_funcs.append([func, name])
@@ -47,8 +46,7 @@ class Collect(object):
threads = []
# Create subdomain collection threads
for collect_func in self.collect_funcs:
func_obj, func_name = collect_func
for func_obj, func_name in self.collect_funcs:
thread = threading.Thread(target=func_obj, name=func_name,
args=(self.domain,), daemon=True)
threads.append(thread)