1

在搞乱python中的随机函数时,我编写了一个程序,我将其保存为random.py。一旦我编写了这个程序,每当我尝试导入随机并利用它的任何功能时,我都会收到这个错误:

Traceback (most recent call last):
  File "testrandom.py", line 3, in <module>
    print random.randint(10, 20)
AttributeError: 'module' object has no attribute 'randint'

关于如何取消覆盖我的随机函数的任何建议?

非常感谢

4

1 回答 1

3

真实random.py的仍然存在,但 Python 正在寻找你的random.py第一个。最好的解决方案是将您自己的模块重命名为其他名称,也许是random_utils.py.

于 2013-10-21T02:33:10.410 回答