python报错 TypeError: string indices must be integers
生活随笔
收集整理的這篇文章主要介紹了
python报错 TypeError: string indices must be integers
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
所以在讀取字典的時(shí)候,最好先判斷類型,然后再查看它是否已經(jīng)有這樣的屬性: type(mydict) == type({}) ? ? ? ? ? ? #檢查不是字典 如果是字典,再看看有沒有這樣的屬性:mydict.has_key('mykey') ? 1、 看看變量是否是字典 ? 2、檢查字典是否有對(duì)應(yīng)的key值? if 'like' in condition:cond_str1 = condition.split('like')[0].strip()cond_str2 = condition.split('like')[1].strip()print(staff_info)ret = filter(lambda x:cond_str2 in str(x[cond_str1]), staff_info) # 這里字典寫錯(cuò)
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/Mr-wangxd/p/9531770.html
總結(jié)
以上是生活随笔為你收集整理的python报错 TypeError: string indices must be integers的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 号外号外!自动化测试工具AutoRunn
- 下一篇: python框架-Django安装使用