V2EX › Python
Python TypeError: argument of type 'type' is not iterable 这个问题怎么解决
By zcsnbb at 2018 年 10 月 22 日 · 16435 次点击self.is_back_test = params['is_back_test'] if "is_back_test" in params else False TypeError: argument of type 'type' is not iterable
这哥问题应该怎么解决
已经尝试过 self.is_back_test = params['is_back_test'] if "is_back_test" in params.keys() else False
使用的是 python3
8 条回复 • 2018-10-22 17:08:50 +08:00
|
1
conn4575 2018 年 10 月 22 日 via Android
检查一下 params 是否是 None?
|
|
2
monkeylyf 2018 年 10 月 22 日
和楼上意见一致。params 应该不是 dict。你可以 print(type(params)) 试试
|
|
3
Yourshell 2018 年 10 月 22 日 via iPhone
你参数的类型不对啊,你先判断是不是可迭代对象啊,报错都这么明显了。
|
|
4
bany 2018 年 10 月 22 日 ```python
if isinstance(params, dcit): return params.get('is_back_test', False) else: return False ``` |
|
5
laike9m 2018 年 10 月 22 日 via Android
请贴上可以复现问题的代码谢谢
|
推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide