Home >Backend Development >Python Tutorial >How Do I Import and Call a Function from a Separate Python File?
Importing and Calling Functions from Separate Python Files
When working with multiple Python modules, it's often necessary to import and call functions defined in other files. In this case, there seems to be confusion when trying to import a function named function from another Python file called file.py.
To import a function from a separate file:
from file import function
function(a, b)
Addressing the Error
However, you mentioned receiving an error indicating that file.py is not a recognized module. This suggests that there may be a naming conflict. Because file is one of Python's core modules, it's advisable to rename file.py to avoid potential issues.
The above is the detailed content of How Do I Import and Call a Function from a Separate Python File?. For more information, please follow other related articles on the PHP Chinese website!