为了账号安全,请及时绑定邮箱和手机立即绑定

'str'对象没有属性'get'-如何告诉python返回的字符串是字典?

'str'对象没有属性'get'-如何告诉python返回的字符串是字典?

qq_笑_17 2021-03-12 15:11:03
当我尝试获取键的值时,我得到一个“ str”对象没有属性“ get”错误,而键的值又是字典的名称。如何告诉python返回的字符串是字典?choices = ['Country','State','Town']chosen = 'Country'country_color = {'Netherlands':'Red','Sweden':'Brown','Ukraine':'Yellow','China':'Pink','Japan':'Black'}state_color = { .... }town_color = { .... }color_data = {'Country': ['col1','country_color'] ,'State': ['col2','state_color'] ,'Town': ['col3','town_color']}    .....color1 = lambda v: country_color.get(v['col1']) # this workscolor2 = lambda v: country_color.get(v[color_data.get(chosen)[0]]) # this too works  color3 = lambda v: color_data.get(chosen)[1].get(v[color_data.get(chosen)[0]]) # but this doesn't work; error - 'str' object has no attribute 'get'    ....
查看完整描述

2 回答

?
人到中年有点甜

TA贡献1895条经验 获得超7个赞

如果您这样编码:

  1. print("Client Name is : {}".format(function).get()) ----错误----

  2. 您将收到此错误“ str”对象没有属性“ get”

  3. print("Client Name is : {}".format(FNEntry.get())) ----固定----


查看完整回答
反对 回复 2021-03-31
  • 2 回答
  • 0 关注
  • 400 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号