I have created this tab-separated file with Vim:
#id #comma separated values
0 d1,d2,cu
1 iii vvv,iii ccc,mmm ccc
The function I use to read the file:
def read_file(filename):
f = open(filename, 'r')
raw = f.readlines()
f.close()
lines = [e.strip().split('\t') for e in raw if not e.startswith('#')]
print lines
out = dict()
for line in lines:
out[line[0]] = line[1].split(',')
return out
I get the following output:
[['0 d1,d2,cu'], ['1 iii vvv,iii ccc,mmm ccc']]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 9, in read_file
IndexError: list index out of range
Even though I am using e.strip().split('\t')
in the function, I get [['0 d1,d2,cu'], ['1 iii vvv,iii ccc,mmm ccc']]
as output instead of [['0','d1,d2,cu'], ['1','iii vvv,iii ccc,mmm ccc']]
My .vimrc file contains the following:
syntax on
colorscheme default
set incsearch
set hlsearch
set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab
Does it mean that tabs in Vim are spaces ? How to make tabs in Vim be the same as \t
in python ?
When I edit the file in Gedit, the python function works as expected.