I am attempting to collect only certain type of data from one file. After that the data is to be saved to another file. The function for writing for some reason is not saving to the file. The code is below:
def reading(data): file = open("model.txt", 'r') while (True): line = file.readline().rstrip("\n") if (len(line) == 0): break elif (line.isdigit()): print("Number '" + line + "' is present. Adding") file.close() return None def writing(data): file = open("results.txt", 'w') while(True): line = somelines if line == "0": file.close() break else: file.write(line + '\n') return None file = "model.txt" data = file somelines = reading(data) writing(data) I trying several things, the one above produced a TypeError (unsupported operand). Changing to str(somelines) did solve the error, but still nothing was written. I am rather confused about this. Is it the wrong definition of the "line" in the writing function? Or something else?
readingreturnsNone, which you store insomelinesbut don't use anyway. Other than that it doesn't actually do anything. How are you expecting to get the data out of thereadingfunction?