How to process a file line by line in Python?

In Python, how to process read a file line by line to process it?

Like those lines in Bash:

while read line ; do
    echo $line
done < ./input.txt

In Python, you can process a file line by line by a for in the file like

with open("./input.txt", "r") as thefile:
  for line in thefile:
    print line
Leave a Reply

Your email address will not be published. Required fields are marked *