import xlrd
wb = xlrd.open_workbook("/Users/susanychen/Documents/pythonPC204/FinalProject/JSO_MasterList_121212.xls")
sh = wb.sheet_by_name(u'Primers')
primer_number = sh.col_values(0)
primer_number.pop(0)
primer_desc = sh.col_values(1)
primer_desc.pop(0)
primer_seq = sh.col_values(7)
primer_seq.pop(0)
primernum = []
primerdesc = []
primerseq = []
for value in primer_desc:
if value != '':
primerdesc.append(value)
index = primer_desc.index(value)
primernum.append(primer_number[index])
primerseq.append(primer_seq[index])
def safe_str(obj):
""" return the byte string representation of obj """
try:
return str(obj)
except UnicodeEncodeError:
return unicode(obj).encode('unicode_escape')
merged_list = []
for item in primernum:
index = primernum.index(item)
desc = safe_str(primerdesc[index])
seq = safe_str(primerseq[index])
temp = [item , desc, seq]
merged_list.append(temp)
import csv
resultfile = open("compiled_info_primer.txt", "wb")
wr = csv.writer(resultfile, dialect = "excel")
for item in merged_list:
wr.writerow(item)