0

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

asked Nov 6, 2011 at 12:23

1 Answer 1

2

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

answered Nov 6, 2011 at 12:25
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, but there's no reason to do that when you can just use file.py and import it.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.