I have several .py files in several folders. I do os.walk and get all names of .py files in list files and prior to that I know that each .py contains a function test() which takes an integer and returns an integer (which is somewhat unique). I am using the following code. Where r is an integer, files contain the path of a py file, for example:
C://users//codebase//user1//int_user_1.py
for fil in files:
spec = importlib.util.spec_from_file_location("test", fil)
foo = importlib.util.module_from_spec(spec)
spec.loader.exec_module(foo)
get_test = foo.test(r)
But the problem here is the line spec.loader.exec_module(foo) is executing all the code in the file fil from line 1 of that particular .py file, but not just the function fil.test(). How can I execute only fil.test() function?
EDIT-1: I am unable to make any changes to the content of fil.py.