I want to use a legacy function that receives a filename as an argument. The function will make some processing after opening that file.
def legacy_f(filename):
with open(filename, 'r') as fh:
# some processing
But I want the processing to happen in some data that is loaded in some variable already, not in a file. Saving the data to a file first is not a solution due to performance. Is there a way to "fool" the legacy function to make it think it is opening a file?
My situation is exactly the one in this question, but the accepted answer there recommends the use of tempfile.NamedTemporaryFile
, which (I believe) does create a file in the disk. I can't afford that.