Opening a file using with keyword
1 2 3 4 5 6 7 8 |
#file open example using "with" (recomemded) with open('raw_corpus.txt') as fp: lines = fp.read().split("n") #here lines contains entire file contents #to access file contents line by line for line in lines: print (line) |
When you run this python script, the contents of the file ‘raw_corpus.txt’ are printed line by line.