Reputation: 203
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
Upvotes: 0
Views: 314
Reputation: 423
You can use "return" to return the values? Don't know if 'I'm missing something, seems too trivial haha. But maybe this:
def fun_input(fName)
ind = pd.read_excel(fName)
p1 = ind[0]
p2 = ind[1]
return {'p1':p1,'p2':p2}
returnValues=fun_input(fname)
p1 = returnValues['p1']
p2 = returnValues['p2']
Upvotes: 0
Reputation: 1947
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)
Upvotes: 1