I have scenario where I am passing a file name and checking if it has argument start as constructor if it has then I have to create instance of that class.
Consider the example where I have a file named test.py which have three class namely A,B,C now only class A has start parameter others have other different parameter or extra parameter.
#test.py
class A:
def __init__(self, start=""):
pass
class B:
def __init__(self, randomKeyword, start=""):
pass
class C:
def __init__(self):
pass
Now I want to write a script which takes test.py as an argument and create instance of A. Till now my progress is
detail = importlib.util.spec_from_file_location('test.py', '/path/to/test.py')
module = importlib.util.module_from_spec(detail)
spec.loader.exec_module(mod)
Bacially I need to write a program which finds init argument of all class in file and create an instance of file with start as init argument.
start". What if it has many different classes in that file that all happen to accept "start", but you're not supposed to use them? You're basically defining an "interface" there, saying "name the parameter of a class I'm supposed to run 'start'". In return that means that name can't be used for anything else inside that file, which is a weird restriction.mainand/or the user passes that name to your program. E.g. in the notation/path/to/test.py:MyClass.startor something like that.