属性错误“模块"对象没有属性“ascii_letters" [英] Attribute Error 'module' object has no attribute 'ascii_letters'
问题描述
为什么我会在下面的代码中收到标题中的错误信息?
Why do I receive the error message in the title from the code below?
因为我没有注意我是如何写ascii"的.谢谢大家
Cause I didn't pay attention to how I wrote "ascii". Thanks everyone
下面的代码在我的 Iphone IDE 上运行良好,但不适用于我的 Windows 7(带 Notepad++ 和命令提示符).我检查了目录以查看是否存在我没有看到的任何 string.py 文件.我在我的桌面上进行了搜索,找到了 4 个文件,其中两个说它们已被遵守.我删除了编译的文件并留下了另外两个.我是菜鸟.
The code below works fine on my Iphone IDE but not on my Windows 7 (w/Notepad++ and Command Prompt). I checked the directory to see if any string.py files existed which I did not see any. I ran a search on my desktop and found 4 files named that, two of which said they were complied. I deleted the compiled files and left the other two. I'm a noob.
import string
import random
x = string.acsii_letters
y = random.choice(x)
print y * 5
推荐答案
应该是 string.ascii_letters
字母而不是 string.acsii_letters
.如果这只是这里代码语句中的一个错字,那么您的猜测一定是正确的,在您的 PYTHONPATH
中还有另一个字符串模块.打开python shell,
It should be string.ascii_letters
letters instead of string.acsii_letters
. If that's a typo in code statement here only, then your guess must be right, there is another string module in your PYTHONPATH
. Open python shell,
import string
print(string.__file__)
确保从正确的路径导入字符串.如果它没有从 PYTHONPATH
中删除该路径.
to ensure string is being imported from right path. If its not remove that path from PYTHONPATH
.
这篇关于属性错误“模块"对象没有属性“ascii_letters"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!