How to include external Python code to use in other files?

You will need to import the other file as a module like this:

import Math

If you don’t want to prefix your Calculate function with the module name then do this:

from Math import Calculate

If you want to import all members of a module then do this:

from Math import *

Edit: Here is a good chapter from Dive Into Python that goes a bit more in depth on this topic.

Leave a Comment