[英]random module doesn't have randint() function
When I call random.randint()
, I get the following error. 当我调用
random.randint()
,出现以下错误。 Can anyone please explain what's happening? 谁能解释一下发生了什么?
$ 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
You've called a script "random.py". 您已将脚本称为“ random.py”。 Rename it so that it isn't shadowing the stdlib module of the same name.
重命名它,以免影响相同名称的stdlib模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.