I am trying to create a temporary file that I write on some lines from another file and then create some objects from the data. I am not sure how to find and open a temporary file so that I can read it. My code is:
with tempfile.TemporaryFile() as tmp: lines = open(file1).readlines() tmp.writelines(lines[2:-1]) dependencyList = [] for line in tmp: groupId = textwrap.dedent(line.split(':')[0]) artifactId = line.split(':')[1] version = line.split(':')[3] scope = str.strip(line.split(':')[4]) dependencyObject = depenObj(groupId, artifactId, version, scope) dependencyList.append(dependencyObject) tmp.close()
Essentially, I just want to make a temporary intermediary document to protect against accidentally overwriting a file.
source share