Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.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-';模块';对象没有属性';randrange';_Python - Fatal编程技术网

Python-';模块';对象没有属性';randrange';

Python-';模块';对象没有属性';randrange';,python,Python,我有两个文件a.py和b.py a.py from b import * #and then some lines of code import random red = random.randrange(1,257) / 256.0 #and then some lines of code b.py from b import * #and then some lines of code import random red = random.randrange(1,257) / 2

我有两个文件a.py和b.py

a.py

from b import *

#and then some lines of code
import random
red = random.randrange(1,257) / 256.0

#and then some lines of code
b.py

from b import *

#and then some lines of code
import random
red = random.randrange(1,257) / 256.0

#and then some lines of code
在运行时,我得到一个错误,说
“module”对象没有属性“randrange”

我不知道为什么会出现这个错误,因为当我在某个虚拟文件中测试它时,试图打印
red=random.randrange(1257)/256.0
,它可以工作。但在这种情况下不是这样


为什么会出现此错误?

您有第三个文件random.py。重命名它。

要确认@ignacio的答案,可以运行
python-v


这将列出所有导入模块及其导入位置。

我已经知道这一点,并删除了random.py文件,但仍保留了pyc文件。因此我们得到了错误。谢谢。这显然是愚蠢的。为什么,为什么,有语言迫使我重命名我的文件(