from xlrd import open_workbook
book = open_workbook('trial.xls')
sheet=book.sheet_by_index(0)
name_email={}
i=0
for row_index in range(sheet.nrows):
if name_email.has_key(sheet.cell(row_index,i).value):
name_email[str(sheet.cell(row_index,i).value.strip())]=sheet.cell(row_index,i+1).value,)
else:
abc = str(sheet.cell(row_index,i).value.strip())
print repr(abc)
print '"{0}"'.format(repr(abc))
# print name_email[abc]
name_email[str(sheet.cell(row_index,i).value.strip())]=sheet.cell(row_index,i+1).value
i+=1
print name_email.keys()
print name_email
输出是:'manoj' "'manoj'" 'dibyendu' "'dibyendu'" 'sourav' "'sourav'" ['dibyendu', 'sourav', 'manoj'] {'dibyendu': (u' d.b@gmail.com',), 'sourav': (u's.b@gmail.com',), 'manoj': (u'm.c@gmail.com',)}
但仍然无法访问 print name_email[abc] 抛出错误 print name_email[abc] KeyError: 'manoj'