Post

PythonPython

j
jordan chris

Posted on 27th February 2024|43 views

0
votes

Python Call Function From Another File

How can I call a function from another file in python?

Answers
P
veerubhotla sowmithri

Posted on 27th February 2024

There are three steps to follow

  • Create a python file having the needed functions.
  • Create another python file then import previous python file into this one.
  • Call the functions defined within the imported file.

Here is the example a python file example.py is created and it has showMsg() function.

#example.py

def showMsg():

    print( "mindmajix")

Now let us create another python file that calls the showMsg() function defined in example.py

# functions defined within example.py

from test import *

  showMsg()

Output:

mindmajix 

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos