Python教科书示例程序中的导入错误

Python教科书示例程序中的导入错误,python,import,Python,Import,我正在学习Python教科书,它在下面的示例程序中包含一个错误: # Random Access # Demonstrates string indexing import random word = "index" print "The word is:", word, "\n" high = len(word) low = -len(word) for i in range(10): position = random.randrange(low, high) prin

我正在学习Python教科书,它在下面的示例程序中包含一个错误:

# Random Access
# Demonstrates string indexing

import random

word = "index"
print "The word is:", word, "\n"

high = len(word)
low = -len(word)
for i in range(10):
    position = random.randrange(low, high)
    print "word[", position, "]\t", word[position]

raw_input("\n\nPress enter to exit.")
Python出现以下错误:

File "C:\Python27\random.py", line 3, in <module>
import random   

File "C:\Python27\random.py", line 11, in <module>
    position = random.randrange(low, high) AttributeError: 'module' object has 
    no attribute 'randrange'
文件“C:\Python27\random.py”,第3行,在
随机输入
文件“C:\Python27\random.py”,第11行,在
position=random.randrange(低、高)AttributeError:“模块”对象具有
没有“randrange”属性
有没有办法解决这个问题?我不熟悉编程和python。
我以前使用过“import random”代码,效果很好。

问题是我使用Python文件夹作为工作目录,并将脚本命名为“random.py”。

不要将文件命名为“random.py”。另外,不要将Python目录用作workspace@JBernardo谢谢,现在可以用了。教科书没有警告过这一点!请不要在问题标题中添加“已解决”一词;将解决方案标记为已接受。对于一个需要更长时间的自我回答,但你的问题可能对将来的其他人也有用,无论是否解决,是否重复。