Call function from another file
Suppose there is a file called test.py which contains some variables and functions inside of it.
test.py is:
text = 'Hello world'
def printhello():
print(text)
add_numbers(a,b):
print("Result is : ", a+b)
To call the function named printhello() in any other python file wherever need to call printhello() function display the text inside of it. This operation done using Python modules. Assume another python file
callfunction.py:
#import all the elements in test.py
from test import *
#call function
printhello()
To limit functions defined in the test.py file:
#import limited functions in test.py
from test import add_numbers
#call function
add_numbers(3,4)