I'm desperatly trying to split a string using Python but the text file I need to parse is a little bit tricky:
- The text file is a comma separated data file
I did the following:
import fileinput
for line in fileinput.input("sample.txt"):
data = line.strip().split(',')
pass
This actually should make the job right ?
Ok now the tricky part: I have some field that contains comma inside like the one below:
"(CONTRACTS OF 5,000 BUSHELS)"
using my code, the script also split this field in 2.
How can I ask python to use comma as a delimiter but not when they are enclosed by "" ?
Thank you in advance for your answers
Crak
passin your code example?The text file is a comma separated data file.I was confused because of the file extension which was a.txt... One day lost for almost nothing :) Thanks.