tmp.txt
line number one
line number two
line number three
tmp.py
#!/usr/bin/env python
# coding=utf-8
def _main():
f = open('tmp.txt')
while [1 for line in [f.readline()] if line]:
print line[:-1]
if '__main__' == __name__:
_main()
And that is what happens when I call the script:
me@yazevnul-mac:tmp$ python tmp.py
line number one
line number two
line number three
Yes I know that this is the wrong way to read the file, but how does the variable line
can be used inside the body of the cycle and why list was not constructed first? So it would be really interesting if some one will tell in details how this code work.