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

当我尝试获取键的值时,我得到一个“ 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 works

color2 = 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'


    ....


qq_笑_17
浏览 401回答 2
2回答

人到中年有点甜

如果您这样编码:print("Client Name is : {}".format(function).get()) ----错误----您将收到此错误“ str”对象没有属性“ get”print("Client Name is : {}".format(FNEntry.get())) ----固定----
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python