Python read file line by line

How to read a text file line by line using Python?

Reading files in python is extremely simple to do. The following is the code:

with open("/path/to/file.txt") as f:
    for line in f:
        linedata = line.split('\t')

Very often, you may want to split each line to an array, you can use the split() method.

Category >> Python  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
<pre><code> 
String foo = "bar";
</code></pre>