I have the following functions to read files, then store them inside variables:
def browseFiles():
filename = filedialog.askopenfilename(initialdir = "/home",
title = "Select a File",
filetypes = (("Text files",
"*.docx*"),
("all files",
"*.*")))
label_file_explorer.configure(text="File Opened: "+ filename)
with open(filename) as fp:
firstfile = fp.read()
def browseFiles1():
filename1 = filedialog.askopenfilename(initialdir = "/home",
title = "Select a File",
filetypes = (("Text files",
"*.docx*"),
("all files",
"*.*")))
label_file_explorer.configure(text="File Opened: "+ filename1)
with open(filename1) as fp:
secondfile = fp.read()
I want to concatenate firstfile and secondfile together, then produce a third file. So, I used :
firstfile += "\n"
firstfile += secondfile
with open ('thirdfile.docx', 'w') as fp:
fp.write(firstfile)
My questions is how to access the variables firstfile and secondfile in each function and use them to produce a third file ?