I have revised this question to make it much more simple.
I am running a program in python 3.x. I want this program to open a file name example.py and run the code inside it. This is the contents of the file:
#example1.py
print('hello world')
#example2.py
print('hello world 2')
#main.py
someMagicalCodeHere(executes example2.py)
#prints hello world
I need to do this without it being an imported file.
The problem with imported files is they are declared beforehand in the main.py. My main.py will be creating example1.py, example2.py etc and filling them with code, and then later referencing back to them as needed. There may be thousands or millions.
This is part of a large project that we are trying to switch over to a new language. We don't know python yet, and we need this concept to be viable to continue learning the language.
I have tried exec(example.py)
I have tried with open('example.py', 'r') as ex: ex.read()
Thanks in advance for the answer, and thanks for all who have answered thus far.