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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -