How do I call a function from another .py file?

First, import function from file.py:

from file import function

Later, call the function using:

function(a, b)

Note that file is one of Python’s core modules, so I suggest you change the filename of file.py to something else.

Note that if you’re trying to import functions from a.py to a file called b.py, you will need to make sure that a.py and b.py are in the same directory.

Leave a Comment