Python Calling Function from Another File

Let us have two files in the same directory. Files are called main.py and another.py.

First write a method in another.py:

def do_something():
    return "This is the do something method"

Then call the method from main.py. Here is the main.py:

import another
print another.do_something()

Run main.py and you will get output like this:

This is the do something method

N.B.: The above code is being executed using Python 2.7 in Windows 10.

Leave a Comment

tech