Importing data from tab-delimited files
Another very common format of flat datafile is the tab-delimited file. This can also come from an Excel export but can be the output of some custom software we must get our input from.
The good thing is that usually this format can be read in almost the same way as CSV files as the Python module csv
supports the so-called dialects that enable us to use the same principles to read variations of similar file formats, one of them being the tab- delimited format.
Getting ready
Now you're already able to read CSV files. If not, please refer to the Importing data from CSV recipe first.
How to do it...
We will reuse the code from the Importing data from CSV recipe, where all we need to change is the dialect we are using as shown in the following code:
import csv filename = 'ch02-data.tab' data = [] try: with open(filename) as f: reader = csv.reader(f, dialect=csv.excel_tab) header = reader.next() data = [row for row in reader] except...