python - Itertools.product 引发 "Error in argument"

标签 python python-3.x ipython python-itertools ipdb

我在这里有点迷路:

我不能在我的代码中使用 itertools.product。这是在 unittest setUp 方法中的一个断点:

ipdb> import itertools
ipdb> itertools
<module 'itertools' (built-in)>
ipdb> itertools.product
<class 'itertools.product'>
ipdb> list(itertools.product([2,7], [1,4]))
*** Error in argument: '(itertools.product([2,7], [1,4]))'

我很确定我没有对模块本身做任何奇怪的事情,因为它在我的代码库中(那里没有未提交的更改):

$ git grep itertools
simple_wbd/climate.py:import itertools

如果我在 Ipython 解释器中尝试这个,它工作正常。

In [1]: import itertools

In [2]: list(itertools.product([2,7], [1,4]))
Out[2]: [(2, 1), (2, 4), (7, 1), (7, 4)]

我什至不知道如何调试它。任何帮助都会很好。

谢谢。

最佳答案

在这个调试器中,list 是一个命令。要访问您想要的内置名称,请在前面加上感叹号:

ipdb> list(itertools.product([2,7], [1,4])
*** Error in argument: '(itertools.product([2,7], [1,4])'
ipdb> !list(itertools.product([2,7], [1,4]))
[(2, 1), (2, 4), (7, 1), (7, 4)]

这不应该是代码本身的问题,只是在调试器中。

关于python - Itertools.product 引发 "Error in argument",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38806295/

相关文章:

python - Cython 缓冲协议(protocol)示例错误

python - 导入错误: No module named 'Kernel'

python - python 正则表达式中的 Re.search 未按预期工作

python - 从 Python 中的相对路径导入

python - 如何让 IPython 5 与 SublimeREPL 一起工作?

python - 如何在 pandas python 中显示多个图表

Visual Studio Code 中的 Python 重构失败

python - Sprite 之间的pygame碰撞

python - 如何将具有不规则列的html代码转换为嵌套的json文件?

python - 从 ipython-notebook 转换为 .py