Here is my goal:
Create a script that accept 2 CSV files and returns a 3rd CSV file containing only the differences.
I am using Python 3.7.2.
Here is my code:
def findFile1():
filename = ## prompts the user to select a .csv file.
with open(filename, 'r') as t1:
fileone = t1.readlines()
return fileone
def findFile2():
filename = ## prompts the user to select another .csv file.
with open(filename, 'r') as t2:
filetwo = t2.readlines()
return filetwo
def saveFile():
filename = ## prompts the user to name and choose a location to save a new .csv file.
fileone = findFile1() ##Here I would just like to readlines from the first CSV file. Not run the whole script again.
filetwo = findFile2() ##Here I would just like to readlines from the second CSV file. Not run the whole script again.
with open(filename, 'w') as outFile:
for line in filetwo:
if line not in fileone:
outFile.write(line)
All I want is to use the return values from the first 2 functions, not call the whole function again.
UPDATE: I was able to solve this with Charles Duffy's suggestion "import functools and put the line @functools.lru_cache() above your functions, and all future calls will reuse the prior invocation's results"