Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Parsing CSV / tab-delimited txt file with Python
- A B C D
- 1 CDCDCDCD
- 2 VDDBDDB
- 3
- 4
- 5
- 6
- 7 DDEFEEF FEFEFEFE
- 8 123456 JONES
- 9
- 10
- 11
- 12
- 13
- 14
- 15 293849 SMITH
- import csv
- mydict = {:}
- f = open("myfile", 'rt')
- reader = csv.reader(f)
- for row in reader:
- print row
- import csv
- from itertools import islice
- entries = csv.reader(open("myfile", 'rb'))
- mydict = {'key' : 'value'}
- for i in xrange(6):
- mydict['i(0)] = 'I(2) # integers representing columns
- range = islice(entries,6)
- for entry in range:
- mydict[entries(0) = entries(2)] # integers representing columns
- lol = list(csv.reader(open('text.txt', 'rb'), delimiter='t'))
- d = dict()
- key = lol[6][0] # cell A7
- value = lol[6][3] # cell D7
- d[key] = value # add the entry to the dictionary
- ...
- my_dict = {}
- for i, line in enumerate(file):
- if (i - 8) % 7:
- continue
- k, v = line.split("t")[:3:2]
- my_dict[k] = v
Add Comment
Please, Sign In to add comment