I am new to Python and trying to learn the language structure.
I understand how for statement and open function work. But cannot explain how this piece of code works, which dumps the content of file sample_log.txt to screen:
for line in open("sample_log.txt"):
print line
These are my questions:
open return a list?The open function returns a file object, they are iterable, so you can loop over it using a for expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With