为什么这个python程序不起作用? AttributeError:'module'对象没有属性

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么这个python程序不起作用? AttributeError:'module'对象没有属性相关的知识,希望对你有一定的参考价值。

我写了一个非常简单的python程序。

#!/usr/bin/env python
import random
x = random.uniform(-1, 1)
print str(x)

我从命令提示符运行它。

python random.py

它返回错误:

Traceback (most recent call last):
  File "random.py", line 2, in <module>
    import random
  File "D:\python practise\random.py", line 3, in <module>
    x = random.uniform(-1, 1)
AttributeError: 'module' object has no attribute 'uniform'

这是一个非常简单的程序,我无法理解我在这里犯了什么错误。

(操作系统:Windows 7; python版本:2.7)

以上是关于为什么这个python程序不起作用? AttributeError:'module'对象没有属性的主要内容,如果未能解决你的问题,请参考以下文章