python字典中给一个键增加值_在Python字典中向单个键添加多个值

Python字典今天真的很吸引我。我一直在堆栈上奔波,试图找到一种方法,将一个新值简单地附加到python字典中的现有键上,但每次尝试都失败,使用的语法与这里相同。在

我要做的是:#cursor seach a xls file

definitionQuery_Dict = {}

for row in arcpy.SearchCursor(xls):

# set some source paths from strings in the xls file

dataSourcePath = str(row.getValue("workspace_path")) + "\\" + str(row.getValue("dataSource"))

dataSource = row.getValue("dataSource")

# add items to dictionary. The keys are the dayasource table and the values will be definition (SQL) queries. First test is to see if a defintion query exists in the row and if it does, we want to add the key,value pair to a dictionary.

if row.getValue("Definition_Query") <> None:

# if key already exists, then append a new value to the value list

if row.getValue("dataSource") in definitionQuery_Dict:

definitionQuery_Dict[row.getValue("dataSource")].append(row.getValue("Definition_Query"))

else:

# otherwise, add a new key, value pair

definitionQuery_Dict[row.getValue("dataSource")] = row.getValue("Definition_Query")

我得到一个属性错误:AttributeError: 'unicode' object has no attribute 'append'

但我相信我所做的与提供的答案相同here

我尝试过其他各种方法,但没有成功地处理其他各种错误消息。我知道这可能很简单,也许我在网上找不到合适的来源,但我被卡住了。有人愿意帮忙吗?在

谢谢,

迈克

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值