3

我正在使用 2to3 转换脚本。我得到的唯一警告是:

RefactoringTool: Line 716: You should use 'operator.mul(None)' here.

原始脚本的第 716 行是:

classes = repeat(None)

我不知道我应该在哪里使用operator.mul(None). repeat()链接到文档)的参考文档表明我可以None毫无问题地通过。那么,我该怎么办?

4

1 回答 1

3

2to3 只是对repeat你的意思感到困惑。它认为您operator.repeat在 Python 2 中使用:

Help on built-in function repeat in module operator:

repeat(...)
    repeat(a, b) -- Return a * b, where a is a sequence, and b is an integer.

而不是itertools.repeat. 老实说,这并不是一个很好的猜测,因为operator.repeat它需要两个参数,但这就是它的猜测。您可以看到文档中列出的转换。

itertools.repeat您可以通过使用完全限定或忽略它来避免警告。

于 2017-04-26T09:21:53.840 回答