2011-12-15 87 views
0

当我打电话给random.randint()时,出现以下错误。任何人都可以请解释发生了什么?随机模块没有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 

回答

13

你已经调用了一个脚本“random.py”。重命名它,以便它不遮盖相同名称的stdlib模块。