你命名了你的脚本bisect.py
;它被导入而不是标准库:
nidhogg:stackoverflow-3.4 mj$ cat bisect.py
import bisect
bisect.bisect_left
nidhogg:stackoverflow-3.4 mj$ bin/python bisect.py
Traceback (most recent call last):
File "bisect.py", line 1, in <module>
import bisect
File "/Users/mj/Development/venvs/stackoverflow-3.4/bisect.py", line 3, in <module>
bisect.bisect_left
AttributeError: 'module' object has no attribute 'bisect_left'
nidhogg:stackoverflow-3.4 mj$ echo 'from bisect import bisect_left' > bisect.py
nidhogg:stackoverflow-3.4 mj$ bin/python bisect.py
Traceback (most recent call last):
File "bisect.py", line 1, in <module>
from bisect import bisect_left
File "/Users/mj/Development/venvs/stackoverflow-3.4/bisect.py", line 1, in <module>
from bisect import bisect_left
ImportError: cannot import name 'bisect_left'
重命名脚本以免掩盖它。