I'm dealing with an application that exports text as as CSV type data. The text is broken up into fields where there was a hard return. I have been trying to use pythons CSV to restore the text.
This is an example of the text:
{"This is an example", "of what I what I have to deal with. ", "Please pick up th following:", "eggs", "milk", "Thanks for picking groceries up for me"}
What is the best way to read this output this text like so:
This is an example of what I have to deal with. Please pick up the following: eggs milk Thanks for picking up the groceries for me
I have tried a number of ways that just haven't been quite right.
Here is what I am doing so far:
import csv
import xlrd
book = xlrd.open_workbook("book1.xls")
sh = book.sheet_by_index(0)
cat = 'Mister Peanuts'
for r in range(sh.nrows)[0:]:
cat_name = sh.cell_value(rowx=r, colx=1)
cat_behavior = sh.cell_value(rowx=r, colx=5)
if sh.cell_value(rowx=r, colx=1) == cat :
csv_reader = csv.reader( ([ cat_behavior ]), delimiter=',')
for row in csv_reader:
for item in row:
item = item.strip()
print(item)
pass
pass
So, the actual cell value that is returned for cat_behavior is the following:
['{"Mister Peanut spent 3.2 hours with {bojangles} fighting', ' "', ' "litter box was cleaned, sanitized and replaced "', ' " Food was replensished - with the best food possible"', ' ', ' "technician - don johnson performed all tasks"}']
I am now trying to take the above and run in through csv.reader to sanitize it and print it to a text file. I am now trying to make the (item) look normal.