我有以下脚本,可以使用:
from xlrd import open_workbook
from string import Template
book = open_workbook('C:/Desktop/input.xls')
sheet = book.sheet_by_index(0)
# read header values into the list
keys = [sheet.cell(0, col_index).value for col_index in xrange(sheet.ncols)]
dict_list = []
for row_index in xrange(1, sheet.nrows):
d = {keys[col_index]: sheet.cell(row_index, col_index).value
for col_index in xrange(sheet.ncols)}
dict_list.append(d)
print dict_list
form=Template('''Please review the following information
Issue Number: $Issue
priority: $Priority
ID: ID
Name: $Name
Date: $Date
''')
first = {u'Priority': 3.0, u'Date': 41894.0, u'Issue': 1233.0, u'Name': u'Ekieta'}
print form.substitute(first)
我希望该部分首先实现自动化,因此它应该始终获取dict_list给出的数据,因此我不必首先打印dict_list然后复制并过去。我该怎么做?