I'm writing a program in Python3.7 and using the statistics module for the mode()
(and more) function. Why is the statistics module in Python3 calling xrange()
when that function doesn't exist in Python3? Is this a bug? I don't think it is because this code worked for me before (I think I was using Python3.7 then too).
Error: NameError: name 'xrange' is not defined
Relavant code:
def mode_tags(self):
self._mode_tags = mode(self._tags_dict.values())
return self._mode_tags
Code referenced from statistics module:
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]
Edit:
I figured out it has something to do with my pipvenv
as the code works fine outside on the host environment.
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"
}
}
}