使用Python3.7时,Mode()函数错误的Traceback显示统计模块调用了`xrange()`。

时间:2019-11-30 04:38:34

标签: python python-3.x python-2.x pipenv pipfile

我正在用Python3.7编写程序,并将统计模块用于mode()(及更多)功能。为什么Python3中的统计模块在Python3中不存在时会调用xrange()?这是错误吗?我不认为这是因为该代码之前对我有用(我认为我当时也使用Python3.7)。

错误:NameError: name 'xrange' is not defined

相关代码:

    def mode_tags(self):
        self._mode_tags = mode(self._tags_dict.values())
        return self._mode_tags

从统计信息模块引用的代码:

  430     # Generate a table of sorted (value, frequency) pairs.
--> 431     table = _counts(data)
    432     if len(table) == 1:
    433         return table[0][0]

    263     # Extract the values with the highest frequency.
    264     maxfreq = table[0][1]
--> 265     for i in xrange(1, len(table)):
    266         if table[i][1] != maxfreq:
    267             table = table[:i]

编辑:

我发现它与我的pipvenv有关,因为代码在宿主环境之外可以正常工作。

Pipfile:

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pysnooper = "*"

[packages]
statistics = "*"

[requires]

Pipefile.lock:

{
    "_meta": {
        "hash": {
            "sha256": "bfce8912bf5c44526c839affc414f071feb36b57777765d1415f10a78d2e3aba"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.7"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "docutils": {
            "hashes": [
                "sha256:6c4f696463b79f1fb8ba0c594b63840ebd41f059e92b31957c46b74a4599b6d0",
                "sha256:9e4d7ecfc600058e07ba661411a2b7de2fd0fafa17d1a7f7361cd47b1175c827",
                "sha256:a2aeea129088da402665e92e0b25b04b073c04b2dce4ab65caaa38b7ce2e1a99"
            ],
            "version": "==0.15.2"
        },
        "statistics": {
            "hashes": [
                "sha256:2dc379b80b07bf2ddd5488cad06b2b9531da4dd31edb04dc9ec0dc226486c138"
            ],
            "index": "pypi",
            "version": "==1.0.3.5"
        }
    },
    "develop": {
        "pysnooper": {
            "hashes": [
                "sha256:7d7684d9d5cf1d026bba6a52e87009eab9458d3265b13059ab1abaea7eee6c93",
                "sha256:85892ef6f4009af7d729e73c7b9e4071a16d5063b1ac9340741c5f192501441b"
            ],
            "index": "pypi",
            "version": "==0.3.0"
        }
    }
}

0 个答案:

没有答案