Guest User

Untitled

a guest
Aug 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. Parsing CSV / tab-delimited txt file with Python
  2. A B C D
  3. 1 CDCDCDCD
  4. 2 VDDBDDB
  5. 3
  6. 4
  7. 5
  8. 6
  9. 7 DDEFEEF FEFEFEFE
  10. 8 123456 JONES
  11. 9
  12. 10
  13. 11
  14. 12
  15. 13
  16. 14
  17. 15 293849 SMITH
  18.  
  19. import csv
  20.  
  21. mydict = {:}
  22. f = open("myfile", 'rt')
  23. reader = csv.reader(f)
  24. for row in reader:
  25. print row
  26.  
  27. import csv
  28. from itertools import islice
  29.  
  30. entries = csv.reader(open("myfile", 'rb'))
  31. mydict = {'key' : 'value'}
  32.  
  33. for i in xrange(6):
  34. mydict['i(0)] = 'I(2) # integers representing columns
  35. range = islice(entries,6)
  36. for entry in range:
  37. mydict[entries(0) = entries(2)] # integers representing columns
  38.  
  39. lol = list(csv.reader(open('text.txt', 'rb'), delimiter='t'))
  40.  
  41. d = dict()
  42. key = lol[6][0] # cell A7
  43. value = lol[6][3] # cell D7
  44. d[key] = value # add the entry to the dictionary
  45. ...
  46.  
  47. my_dict = {}
  48. for i, line in enumerate(file):
  49. if (i - 8) % 7:
  50. continue
  51. k, v = line.split("t")[:3:2]
  52. my_dict[k] = v
Add Comment
Please, Sign In to add comment