Mode()函数错误的回溯显示,当使用Python3.7时,统计模块会调用xrange()。

问题描述 投票:1回答:1
我正在用Python3.7编写程序,并将统计模块用于mode()(及更多)功能。当Python3中不存在该函数时,为什么Python3中的统计模块调用xrange()?这是错误吗?我不认为这是因为此代码之前对我有用(我

think

当时也使用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" } } }

我正在用Python3.7编写程序,并将统计信息模块用于mode()(及更多)功能。为什么在...
python python-3.x python-2.x
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.