code_junkie

How to quickly parse a list of strings

Nov 12th, 2011
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. >>> 'abc,foo,bar'.split(',')
  2. ['abc', 'foo', 'bar']
  3.  
  4. In: 'abc,"a string, with a comma","another, one"'
  5. Out: ['abc', 'a string, with a comma', 'another, one']
  6.  
  7. import csv
  8.  
  9. input = ['abc,"a string, with a comma","another, one"']
  10. parser = csv.reader(input)
  11.  
  12. for fields in parser:
  13. for i,f in enumerate(fields):
  14. print i,f # in Python 3 and up, print is a function; use: print(i,f)
Add Comment
Please, Sign In to add comment