The readlines() method for file objects return the lines as a list (or is it a tuple?)
however each element contains the \n character which prevents the element from being used in another function. How do I remove the \n character from the elements?
I have made some code which Will make return the two lines after the word "path" in a text file.
The return statement will return the line with the \n character. That's where the problem i mentioned arises
def rec_paths(files): f=open(files) g=f.readlines() line=1 for a in g: if 'path' in a: #print(g[line],end='') #print(g[line+1],end='') return(g[line]) line=line+1 else: line=line+1 continue print(rec_paths('C:\\Documents and Settings\\folderX\\Desktop\\t.txt'))
(I can use end=' ' for the print statements but not for the return statements to get rid of the \n)