Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

Set_up: I have a .py file for each function I need to use in a program.

In this program, I need to call the function from the external files.

I've tried:

from import function(a,b)

But I get the error:

ImportError: No module named ''; the file is not a package

How do I fix this problem?

1 Answer

0 votes
by (106k points)

If you want to call a function from another file in Python then there isn't any need to add at the time of importing. You just need to write from file import function, and then call the function using function(a, b)and you are done. Now why not to use is because it  may not work, the file is one of Python's core modules, so it is better that you change the name of your file.

And an important note here that if you're trying to import some functions from file to a file called, make sure that and are in the same directory.

Wanna become an Expert in python? Come & join our Python Certification course

Related questions

0 votes
4 answers
0 votes
2 answers
0 votes
1 answer
+3 votes
2 answers

Browse Categories