Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
意外地重写了;“随机”;用Python创建类。现在无法使用任何随机变量。功能_Python_Random - Fatal编程技术网

意外地重写了;“随机”;用Python创建类。现在无法使用任何随机变量。功能

意外地重写了;“随机”;用Python创建类。现在无法使用任何随机变量。功能,python,random,Python,Random,在python中处理random函数时,我编写了一个程序,保存为random.py。一旦我编写了这个程序,每当我尝试导入random并使用它的任何函数时,我都会遇到以下错误: Traceback (most recent call last): File "testrandom.py", line 3, in <module> print random.randint(10, 20) AttributeError: 'module' object has no attri

在python中处理random函数时,我编写了一个程序,保存为random.py。一旦我编写了这个程序,每当我尝试导入random并使用它的任何函数时,我都会遇到以下错误:

Traceback (most recent call last):
  File "testrandom.py", line 3, in <module>
    print random.randint(10, 20)
AttributeError: 'module' object has no attribute 'randint'
回溯(最近一次呼叫最后一次):
文件“testrandom.py”,第3行,在
打印random.randint(10,20)
AttributeError:“module”对象没有属性“randint”
有没有关于如何取消重写随机函数的建议


非常感谢

真正的
random.py
仍然存在,但是Python首先找到了您的
random.py
。最好的解决方案是将您自己的模块重命名为其他模块,如果您没有将其保存在Python安装的
Lib
目录中(即,如果您没有实际覆盖Python附带的
random.py
),则可能是
random_utils.py

),只需重命名你的
random.py
。将你的
random.py
重命名为与标准库不一致的名称?如果你这样做了。。。也许将Python重新安装到其他位置,然后将random.pyc/random.py文件复制到实际安装的
Lib
目录中。@Max\u Wallace,在这种情况下,从Python存储库获取
random.py
会更容易。