Is it possible to run another Python File from a Main Python File. For example:
I have a file Main.py and its servers as the main directory for the following files:
- Surface Area Calculator
- Scientific Calculator
How would you import a Python file to them. I was hoping to do this so I can keep myself organized.
Could that possible open a file with a .txt format but written in python?
Thanks
1 Answer 1
You don't need to point a Python file to them, you just need the import keyword to do that.
So, from your Main.py file you can do:
from other_python_file import SurfaceAreaCalculator, ScientificCalculator
This way you will "run" other_python_file.py file within Main.py.
If you want to run content from a TXT file, I guess you could use eval or execfile to do that. Don't know if it is such a good idea though...
1 Comment
file.py and import it.