I have a function in Python which takes in a "reader" (I hope that's the right term). Basically the function should be able to use a file, sys.stdin etc. It then has to read all the lines and store them intro a string.
Currently my function calls look something like:
read_data (sys.stdin, sys.stdout)
read_data ("file.txt", "fileout.txt")
and the function itself looks like:
def read_data (reader, s) :
str = ""
str = r.readline()
line = str
while line != "" and line != None and line != '\n':
line = r.readline()
str = str + line
When I run the code and paste the input into the console to test, it actually is able to read all lines including the last line but after that it gets stuck in the "line = readline()". I'm not sure what I'm doing wrong, any help would be greatly appreciated. Thank you
IOobject. Duck-wise, you're basically looking for any object that implementsreadlineand line != '\r\n'. To keep things simpler you may want to rephrase the if asif not line in ["", ...]: