Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
127 views
in Technique[技术] by (71.8m points)

python - Attribute Error 'module' object has no attribute 'ascii_letters'

Why do I receive the error message in the title from the code below?

Edit: Cause I didn't pay attention to how I wrote "ascii". Thanks everyone

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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__)

to ensure string is being imported from right path. If its not remove that path from PYTHONPATH.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...