Python, импорт нескольких классов модуля из функции
У меня есть скрипт 1:
import sys
class Test:
def print_method(self):
TestClass1().myclassfunc()
def myfunc(path_to_module):
sys.path.append(path_to_module)
from mymodule import TestClass1, TestClass2, TestClass3, ..., TestClass15, TestClass16
a = Test()
a.print_method()
myfunc(r'D:\Programming\CALCULATIONS\sandbox')
В этом скрипте я хочу импортировать все классы из модуля, который импортируется через sys внутри функции myfunc. Модуль выглядит так:
class TestClass1:
def myclassfunc(self):
return 'TestClass method'
class TestClass2:
...
class TestClass3:
...
...<и еще много классов, которые нужны>..
class TestClass15:
...
class TestClass16:
...
При вызове функции myfunc ловлю следующую ошибку:
Traceback (most recent call last):
File "<path>", line 26, in <module>
myfunc()
File "<path>", line 23, in myfunc
a.print_method()
File "<path>", line 15, in print_method
TestClass1().myclassfunc()
NameError: global name 'TestClass1' is not defined