我正在用 Python3.7 编写一个程序,并将统计模块用于mode()
(和更多)功能。xrange()
当 Python3中不存在该函数时,为什么会调用 Python3 中的统计模块?这是一个错误吗?我不认为这是因为这段代码以前对我有用(我想我当时也在使用 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
的代码有关,因为代码在主机环境之外运行良好。
点文件:
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
pysnooper = "*"
[packages]
statistics = "*"
[requires]
管道文件.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"
}
}
}