-1

I am new to Python and I want to know am controlling the flow of the program correctly. I am wondering if the following method is the correct way to return a value from a method.

extract_nouns() retunes an empty string if there are no nouns in news_story, the same with extract_numbers(). If search terms.

find_news() returns a list of Story objects if there are any stories, or None if no news story are found.

find_similar_news_stories() returns None unless there is a story to return.

Is this correct, or does it look wrong? Should I explicitly return None if I find no stories. Should I pass an empty list from find_news() to the method that calls find_similar_stories() and handle the checking of list there?

def find_similar_news_stories(self, news_story):
    nouns = self.extract_nouns(news_story)
    numbers = self.extract_numbers(news_story)
    search_terms = nouns + numbers
    if search_terms != "":
        stories = self.find_news(search_terms)
        if stories != None:
            return stories
        stories = self.find_news(nouns)
        return stories
bloopiebloopie
  • 309
  • 1
  • 4
  • 11

1 Answers1

0

It can be of any ways

If the method is called by another method for just process then pass the result as it is thus it should be explicitly handled by the calling method.

If the method is call by end user he need to know the result of the process so the handling should be done in this method itself.

Hari
  • 334
  • 4
  • 16