f.readlines() will load the file in a list entirely, which depending on the size of the file and the available memory may not be desirable.
Opening a file returns an iterator, making .readlines() unnecessary:
path = "/Users/Desktop/test/"
# Read every file in directory
for filename in os.listdir(path):
with open(filename, "r") as f:
# Read each line of the file
for line in file:
print line.split()
• 0 views
•
link
This is a loop sequentially opening each file and printing that. How is this different from what you want?