我正在尝试制作一个字典details
,其中有3个键Username
、Password
、Emailid
,每个键都包含多个值。我正在尝试为Excel工作簿中的键添加值。你知道吗
我想访问字典的每个特定值
details{"Username":Value1,"Password":Value1,"Emailid":Value1}
等等。你知道吗
**立即更新代码
我试着从excel中读取和存储键的值及其对应的数据它自己。这个是更新代码
import openpyxl
wb = openpyxl.load_workbook('user_details.xlsx')
WSheet = get_sheet_by_name('Sheet1')
# get the active working sheet 1
print('Reading rows...')
# read header values into the list
keys = [sheet.cell(0, col_index).value for col_index in xrange(sheet.ncols)]
print "keys are", keys
dict_list = []
for row_index in xrange(1, sheet.nrows):
assetData= {keys[col_index]: sheet.cell(row_index, col_index).value
for col_index in xrange(sheet.ncols)}
dict_list.append(d)
print dict_list
Trying to print the value
for k,v in assetData.items():
Print(%s "hi %s ,Records show that you have not paid dues " % (+ str(assetData[assettagtype["k"]]) +str(assetData[assettagname["k"]]))
# this line of code is just an idea ,syntactically incorrect
样本数据:
username password emailid
A123 alpha abc@xyz.com
b123 tango pqr@xyz.com
c123 charlie muv@xyz.com
我不确定这是否是你要找的,但按照你在这里说的:
我猜你想迭代字典并得到每个值。为此,可以使用
dict.items()
语法:如果只需要这些值,可以使用
dict.values()
:相关问题 更多 >
编程相关推荐