Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6563819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:53:36+00:00 2026-05-25T13:53:36+00:00

I need to handle a bunch of similar but exclusively called function from a

  • 0

I need to handle a bunch of similar but exclusively called function from a single method. e.g. (maybe not a great example)

class Util(object):
    def method1(self):
        return "method1", [1,2,3]

    def method2(self):
        return "method2", {"1":4, "2":5, "3":6}

    def method3(self):
        return [1,2,3], "method3", {"1":4, "2":5, "3":6}

    def call_method(self, method_func):
        if method_func.__name__ == "method1":
            (name, dict_values) = self.method_func()
        if method_func.__name__ == "method2":
            (name, list_values) = self.method_func()
        if method_func.__name__ == "method3":
            (list_values, name, dict_values) = self.method_func()
        # How best to manage a return for 3 optional, but not inter-dependent values?
        return name, dict_values, list_values

if __name__ = "__main__":
    u = Util()
    (name, dict_values, list_values) = u.call_method(Util.method1)

The call_method() return is what I’m trying to visualize here. I’ve got a bunch of exclusive sub-calls I need to make and I need to massage them into something that can be returned.

Would it be easier to just stuff them into Util class member variables? And whoever implements u.call_method() will simply need to know what to look for?

Before anyone complains about the design in the first place, it’s not mine. I simply need to expose a consistent API and an interested to hear opinons on how to handle a return like this. It’s not easily normalized, and though a missing trailing return value will pass the Runtime, a leading one won’t.

Any tips would be great! Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:53:37+00:00Added an answer on May 25, 2026 at 1:53 pm

    If you need to group several values often an approach is using a dictionary… i.e. changing your code to:

    ...
    def method1(self):
        return {"name": "method 1",
                "list": [1, 2, 3]}
    

    Something that is possible in Python is to use an object instead of a dictionary to make the code nicer to read:

    class Bunch:
        def __init__(self, **kwargs):
            self.__dict__.update(kwargs)
    
    ...
    def method1(self):
        return Bunch(name="method1",
                     list=[1, 2, 3])
    

    so that the caller can use result.name instead of result["name"].

    Another option that recently got standardized in Python is the NamedTuple.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to handle events of two different types but I'm running into the
I need to handle strings in my php script using regular expressions. But there
I am writing a search engine (why not hey?) and need to handle navigating
I am writing some Ruby code, not Rails, and I need to handle something
I need to create something similar to how MVC invokes an Method(Action) and also
I'm trying to handle a bunch of files, and I need to alter then
For a project I need to handle audio in an iPhone app quite special
I'm writing a batch (.bat) script and I need to handle the case in
I have a problem with NCurses ... i need to handle all keys like
I'm using IIS7 and ASP.NET. Basically building a simple CMS and need to handle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.