Reading in data from file using regex in python -
i have data file tons of data like:
{"passenger quarters",27.`,"cardassian","not injured"},{"passenger quarters",9.`,"cardassian","injured"},{"passenger quarters",32.`,"romulan","not injured"},{"bridge","unknown","romulan","not injured"}
i want read in data , save in list. having trouble getting exact right code exact data between { }. don't want quotes , ` after numbers. also, data not separated line how tell re.search begin looking next set of data?
at first glance, can break data chunks splitting on string },{
:
chunks = data.split('},{') chunks[0] = chunks[0][1:] # first chunk started '{' chunks[-1] = chunks[-1][:-1] # last chunk ended '}'
now have chunks like
"passenger quarters",27.`,"cardassian","not injured"
and can apply regular expression them.
Comments
Post a Comment