'Pass a generated data frame from one function to another

I am working on a application that takes multiple excel files from the user, does some stuff to them and returns a new excel file. The problem I am encountering is that I do not know how to input the paths the user gives into my compile function.

This is the function that asks the user for their input upon a button press.

def getFile1():
    dat1 = filedialog.askopenfilename(
        initialdir = "/", title = "File Selection",
        filetypes = (("Excel Files", "*.xlsx"), ("All Files", "*.*")))
    lbl1.config(text=dat1)
    df1 = pd.read_excel(r'' + str(dat1), skiprows = 1)
    return df1

For test purposes, lets say I want to print the .head() of the data frame using the compile function.

def compile():
    print(df1.head())

How do I do this? Simply passing df1 like def compile(df1): tells me that it's missing the required positional argument. I tried a few other things but all to no avail.

Edit: I tried to avoid writing the full code in order to keep the post short and concise but for added clarity, here it is with all the fluff taken out.

from tkinter import *
from tkinter import filedialog
import os.path
from tkinter import ttk
from pandas import *
import pandas as pd

def getFile1():
    dat1 = filedialog.askopenfilename(
        initialdir = "/", title = "Select File",
        filetypes = (("Excel Files", "*.xlsx"), ("All Files", "*.*")))
    lbl1.config(text=dat1)
    df1 = pd.read_excel(r'' + str(dat1), skiprows = 1)
    print(df1.head())
    return df1

def compile(df1):
    print(df1.head())


master = Tk()

lbl1 = Label(width = 70)
lbl1.grid(row = 1, column = 1)

Button(text="Excel File", command=getFile1, width = 30, height = 2).grid(row=1, column=0)
Button(text="Execute Programm", command=compile, width = 30, height = 2).grid(row = 2, column = 0)

master.mainloop()


Solution 1:[1]

if you are using class it should be:

class MyCuteClass():

 def compile (self, df1):
  ...

 def callCompile(self):
  ...
  self.compile(sendingDf1)

Usage

myclass = new MyCuteClass()
myclass.compile(yourDf1)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Forbidden