I am desperately trying to break a string using Python, but the text file I need for parsing is a bit more complicated:
- A text file is a comma delimited data file
I have done the following:
import fileinput
for line in fileinput.input("sample.txt"):
data = line.strip().split(',')
pass
Does this really have to do the job right?
Ok now the tricky part: I have a field containing a comma inside, as shown below:
"(CONTRACTS OF 5,000 BUSHELS)"
using my code, the script will also split this field by 2.
How can I ask python to use a comma as a separator, but not when they are enclosed in "???
Thank you in advance for your answers.
Crack
Crack source
share