Click here to Skip to main content
15,311,151 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
import random
from urllib.request import urlopen
import sys


WORD_URL = "http://learncodethehardway.org/words.txt"

WORDS = []


PHRASES = {
if len(sys.argv)  == 2 and sys.argv[1]  == "english":
    PHRASE_FIRST = True


else:
    PHRASE_FIRST = False



    for word in urlopen(WORD_URL).readlines():
        WORDS.append(str(word.strip(), encoding = "utf-8"))


        def convert(snippet, phrase):
            class_names = [w.captilaize() for w in
            random.sample(WORDS, snippet,count("%%%"))]


            other_names =  random.sample(WORDS, snippet,count("%%%"))
            results = []
            param_names = []



            for i in range(0 , snippet.count("@@@")):
                param_count = random.ranit(1,3)
                param_names.append(' ,'.join(
                    random.sample(WORDS,param_count)))


                for sentence in snippets, phrase:
                    result = sentence


# fake class names

for word in class_names:
    result = result.replace("%%%", word, 1)



    for word in other_names:
        result = result.replace("***", word, 1)


        for word in param_names:
            result = result.replace("@@@", word,1)
            results.append(result) 
            



   # Keep goin until they hit CTRL + D  


try:
    while True:
        snippets = lists(PHRASES.keys())
        random.shuffle(snippets)

        for snippet in snippets:
            phrase = PHRASE[snippet]
            question, answer = convert(snippet, phrase)

            if PHRASE_FIRST:
                question , answer = answer , question

                print(question)



                input(" > ")

                print(f"ANSWER: {answer}")

except:
    print("Bye")

The error i get is :
ImportError: cannot import name 'ascii_letters'

What I have tried:

I tried to write it like import utllib.urlopen but it showed the syntax error.
Posted
Updated 12-Dec-18 23:29pm
v2
Comments
Richard MacCutchan 13-Dec-18 4:39am
   
There is no import ascii_letters statement in the above code.
Member 14068174 13-Dec-18 4:55am
   
That, s the actual problem I don't, t know why it showing this error if there is no import ascii_letters statement in the code
Richard MacCutchan 13-Dec-18 5:08am
   
Sorry, but I cannot guess where that error appears in your program. You need to give more information.

1 solution

A simple google on the error message takes you right to the solution: cannot import name 'ascii_letters' - Google Search[^]
The top link explains the problem and it's solution: Python requests module import error - Stack Overflow[^]

If you get an error message you don;t understand, start by Googling it - you can save yourself a lot of time!
   
Comments
Member 14068174 16-Dec-18 9:31am
   
I ALREADY WENT THROUGH THIS BEFORE COMING HERE!
OriginalGriff 16-Dec-18 10:04am
   
1) DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously.
2) Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. So if you've tried something, then the "What I have tried" section is probably a good place to tell us this if you won't want us to assume you haven't.
Member 14068174 17-Dec-18 0:42am
   
haha.. i did,nt knew this man. But one thing i wanna tell you brother , i wanna know that who has made these rules?
OriginalGriff 17-Dec-18 1:55am
   
https://www.google.com/search?q=netiquette&oq=neti&aqs=chrome.2.69i57j0l5.4150j0j7&sourceid=chrome&ie=UTF-8

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900