0

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?

Community
  • 1
  • 1
androidBegginer
  • 795
  • 5
  • 14
  • your indentation is incorrect. `except` should be at the same indentation level as `try` – jkr Nov 06 '16 at 06:00

1 Answers1

3

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.

Dan D.
  • 73,243
  • 15
  • 104
  • 123