Here's what I want to do:
import copy
def printtext(swefile):
for row in swefile:
print(row)
text = open("wordsv.txt","r",encoding="utf-8")
text2 = copy.copy(text)
printtext(text)
print(text2.readlines())
But it is not possible, TypeError: cannot serialize '_io.TextIOWrapper' object. So I wonder if there is a good method for "cloning" the text variable, so that I could print all the lines again. I know that I could just read the file again, but that answer does not solve the bigger problem I have so any suggestion on how to get this done is helpful.
Here's the larger context as I haven't been able to solve my problem with your suggestions:
with open(textfilename, "r", encoding = "utf-8") as swefile:
for row in swefile:
word = row.strip()
tempfile = copy.copy(swefile)
l = getFurthest(word,tempfile)
The thing that I want to happen here is that i want to send the portion of swefile that has not been read yet (i.e. iterated over yet by the for loop) to getFurthest()! And I can't send swefile because that will make the whole thing read so the iterations in the for loop will stop, right? So how can I send only the portion of the textfile that has been read to getFurthest() while still being able to iterate over the rest of it after?