Skip to main content
added 233 characters in body
Source Link
Keith
  • 43.2k
  • 11
  • 61
  • 77

All you need to do is use the file object as an iterator.

for line in open("log.txt"):
    do_something_with(line)

Even better is using context manager in recent Python versions.

with open("log.txt") as fileobject:
    for line in fileobject:
        do_something_with(line)

This will automatically close the file as well.

All you need to do is use the file object as an iterator.

for line in open("log.txt"):
    do_something_with(line)

All you need to do is use the file object as an iterator.

for line in open("log.txt"):
    do_something_with(line)

Even better is using context manager in recent Python versions.

with open("log.txt") as fileobject:
    for line in fileobject:
        do_something_with(line)

This will automatically close the file as well.

Source Link
Keith
  • 43.2k
  • 11
  • 61
  • 77

All you need to do is use the file object as an iterator.

for line in open("log.txt"):
    do_something_with(line)