Search code examples
pythonpython-3.xfunctioncall

call a function with multiple outputs defined in another file in another file


Let assume that I have file named Input.py that have the following function:

import pandas as pd    

def fun_input(fName)
     ind = pd.read_excel(fName)
     p1 = ind[0]
     p2 = ind[1]

Now, I like to call this function in another file named Main.py and use the values of p1 and p2 for a given value of fName (that I will define in the main file). I have written a code like below but I am not how I should make it works. Please help me.

from Input import fun_input

fName = '1.xlsx'
p1 = fun_input(fName).p1
p2 = fun_input(fName).p2

Solution

  • import pandas as pd    
    
    def fun_input(fName)
         ind = pd.read_excel(fName)
         return ind[0], ind[1]
    

    In the other file

    from Input import fun_input
    
    fName = '1.xlsx'
    p1, p2 = fun_input(fName)