Call a function from another file? Call a function from another file? python python

Call a function from another file?

There isn't any need to add while importing. Just write from file import function, and then call the function using function(a, b). The reason why this may not work, is because file is one of Python's core modules, so I suggest you change the name of your file.

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

First of all you do not need a .py.

If you have a file and inside you have some functions:

def b():  # Something  return 1def c():  # Something  return 2

And you want to import them in you have to write

from a import b, c

You can do this in 2 ways. First is just to import the specific function you want from To do this use

from file import function

Another way is to import the entire file

import file as fl

Then you can call any function inside using