split csv file with comma
Asked by
judy johnson
I need to parse out a csv file but within a line, but there may be a comma within a field that throws off the parsing
if the line = "tom,jones,123 street apt 6", then line.split(',') parses correctly with 3 elements but
if the line = "tom,jones,123 street, apt 6", then the line.split(',' parses correctly with 4 elements but I need "123 street, apt 6"
I have tried putting double quotes around the address, single quotes around the address, \ after street. I have tried using split(',',3). I've tried using rsplit(',',3).
How do I deal with a comma within a field?
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- Python Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask judy johnson for more information if necessary.
To post a message you must log in.