当我致电random.randint()
时,收到以下错误消息。有人可以解释一下发生了什么吗?
$ python
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "random.py", line 4, in <module>
print >>file,random.randint(100,10000)
AttributeError: 'module' object has no attribute 'randint'
>>> random.randint(100)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'random' is not defined
答案 0 :(得分:13)
你已经调用了一个脚本“random.py”。重命名它,使其不会遮挡同名的stdlib模块。