Calling Function of custom Python (.py) file in Python programming. Functions are used to divide a large program into sub-programs for easy control. All these sub-programs are called sub-functions of the program.
First of all goto left side Project
pane and right click on MyProgram
and
goto New
-> and select Python File
.
In New Python file
dialog in Name:
write MyFile
and click on OK
button.
Write the following code in MyFile.py
file.
def fun(): #fun()' is name of Function.
print("This is Simple Function in MyFile")
def fun2(): #'fun2()' is name of Function.
print("This is Another Simple Function in MyFile")
Write the following code in main program MyProgram.py
file.
import MyFile #importing 'MyFile' File.
MyFile.fun() #calling 'fun()' function of 'MyFile' File.
MyFile.fun2() #calling 'fun2()' function of 'MyFile' File.
Write the following code in main program MyFile.py
file.
def fun(): #fun()' is name of Function.
print("This is Simple Function in MyFile")
def fun2(): #'fun2()' is name of Function.
print("This is Another Simple Function in MyFile")
Write the following code in main program MyFile2.py
file.
def fun3(): #fun3()' is name of Function.
print("This is Simple Function in MyFile2")
def fun4(): #'fun4()' is name of Function.
print("This is Another Simple Function in MyFile2")
Write the following code in main program MyProgram.py
file.
import MyFile #importing 'MyFile' File.
import MyFile2 #importing 'MyFile2' File.
MyFile.fun() #calling 'fun()' function of 'MyFile' File.
MyFile.fun2() #calling 'fun2()' function of 'MyFile' File.
MyFile2.fun3() #calling 'fun3()' function of 'MyFile2' File.
MyFile2.fun4() #calling 'fun4()' function of 'MyFile2' File.
Write the following code in MyFile.py
file.
def fun(): #fun()' is name of Function.
print("This is Simple Function in MyFile")
def fun2(): #'fun2()' is name of Function.
print("This is Another Simple Function in MyFile")
Write the following code in MyFile2.py
file.
def fun(): #fun()' is name of Function.
print("This is Simple Function in MyFile2")
def fun2(): #'fun2()' is name of Function.
print("This is Another Simple Function in MyFile2")
Write the following code in MyProgram.py
file.
import MyFile #importing 'MyFile' File.
import MyFile2 #importing 'MyFile2' File.
MyFile.fun() #calling 'fun()' function of 'MyFile' File.
MyFile.fun2() #calling 'fun2()' function of 'MyFile' File.
MyFile2.fun() #calling 'fun()' function of 'MyFile2' File.
MyFile2.fun2() #calling 'fun2()' function of 'MyFile2' File.
Write the following code in MyFile.py
file.
import MyFile2 #importing 'MyFile2' File.
def fun(): #fun()' is name of Function.
print("This is Simple Function in MyFile")
MyFile2.fun2() #calling 'fun2()' function of 'MyFile2' File.
Write the following code in MyFile2.py
file.
def fun2(): #'fun2()' is name of Function.
print("This is Simple Function in MyFile2")
print("After Calling Functions")
Write the following code in MyProgram.py
file.
import MyFile #importing 'MyFile' File.
print("Before Calling Functions")
MyFile.fun() #calling 'fun()' function of 'MyFile' File.