user1031493
user1031493

Reputation: 1131

Running Python file within its self

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:

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

Upvotes: 0

Views: 89

Answers (1)

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181280

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...

Upvotes: 2

Related Questions