python報錯 TypeError: string indices must be integers


所以在讀取字典的時候,最好先判斷類型,然后再查看它是否已經有這樣的屬性:
type(mydict) == type({})             #檢查不是字典
如果是字典,再看看有沒有這樣的屬性:mydict.has_key('mykey')  
1、 看看變量是否是字典   2、檢查字典是否有對應的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)       # 這里字典寫錯 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM