DEV Community

Srinivasulu Paranduru
Srinivasulu Paranduru

Posted on • Edited on

How to reference other python files and functions

Steps required to refer one python file in other python file

  1. Create two python files mymodule.py & myprogram.py based on the code given below
  2. Then execute python file - myprogram.py

mymodule.py

def my_func() : 
  print("Hey I am in mymodule.py")
Enter fullscreen mode Exit fullscreen mode

myprogram.py

from mymodule import my_func
my_func()
Enter fullscreen mode Exit fullscreen mode

Now to execute the python file myprogram.py

python3 myprogram.py

Output:
Hey I am in mymodule.py

Top comments (0)