0
votes

When in run my python script, i get the following result:

Try again

None

import wikipedia
import time


def wiki_search(word):
    try:
        wikipedia.set_lang("es")
        wiki_result = wikipedia.summary(word, sentences=1, auto_suggest=True,   redirect=True)
        return wiki_result
    except wikipedia.exceptions.WikipediaException as e:
        return translate(e)
    
def translate(text):
   if "match" in str(text):
       print "Try again"
   else:
       print text

print wiki_search("Mark Zuckerb")
time.sleep(5)

Why "None" appear and how to remove it from the output?

1
your indentation is incorrect. except should be at the same indentation level as try - jakub

1 Answers

3
votes

The function translate(text) returns None because it has no return statement that is reached when it is called. Every function ends with an implicit return None.