欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

python报错 TypeError: string indices must be integers

发布时间:2025/3/15 python 62 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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) # 这里字典写错

 

 

转载于:https://www.cnblogs.com/Mr-wangxd/p/9531770.html

总结

以上是生活随笔为你收集整理的python报错 TypeError: string indices must be integers的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。