I have several files with data in it that I need to use. I have written some code to import this data from one file, and then set up another function that depends on a list I read the data into to manipulate/recall the data.
I would like to generalize my importing function to be able to do the following:
- Take as input a specific filename that I want imported
- Perform the necessary importing (e.g. using the
Importfunction) and manipulate the data to prepare it for use. For my case, this involves putting the imported data into a list.
- Return a function that I can call which will be able to perform the necessary calculations to return the appropriate value from the list I imported.
The issue here is the variable I store the list in. As far as I can tell, either the list is a variable outside the scope of the function (a pain), or I need it to be a variable local to the function and I have to go through the process of reading the file every time I call the function (which is slow).
Is there a way to make a function basically "cache" some value, local to that function? I don't want to have to generate this list every time I call the function, nor do I want a bunch of extra variables lying around that I don't use.