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 7718735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:14:21+00:00 2026-06-01T03:14:21+00:00

I have a class with like 50 methods. class MyProgram(object): def method1(self): pass def

  • 0

I have a class with like 50 methods.

class MyProgram(object):
    def method1(self):
        pass
    def method2(self):
        pass
    # and so on  

Its that big because my Class is also my program, i call myProgram.py via the console and many methods are options like:

myProgram.py --method1 --method2

On the one hand it is really easy for me to use the methods like this. On the other hand the code is just not readable anymore. If I have to change two things, I have to go 1000 lines up and then 2000 lines down to just changes some dependencies or add a new feature like method999().

How can I split my class and still have something like myProgramm.py –method1 –method2 ?
Its important that I can call my program like this to do some cronjobs.

(I’m convinced that there is a really easy solution to this, but I just can’t think about it now)

EDIT: a better example of my god class.

class myprogram(object):
    def __init__(self)
        self.prepare()
    def prepare(self):
        # some initializations
        self.prepareCommands()
    def prepareCommands(self):
        self.initCommand("--updateDatabase", self.updateDatabase)
        self.initCommand("--getImages", self.getImages)
        # and so on
    def initCommand(self, cmd, func):
        options = sys.argv
        for option in options:
            if option.find(cmd)!=-1:
                return func()
    # my commands
    def updateDatabase(self):
        #...
    def getImages(self):
        #...
if __name__ == "__main__":
    p = myprogram()

EDIT2: After researching a little I think I got a good solution. I will update everything when I’ve rewritten my programm. 🙂

  • 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-06-01T03:14:23+00:00Added an answer on June 1, 2026 at 3:14 am

    Could you use an extra level of indirection? (This is an old Computer Science axiom:-)

    Edit:

    So instead of using the actual method names on the command line, use a dictionary to call the actual code. The dictionary maps the command line ‘names’ to the actual function or object+method that gets called. Then you would have more flexibility about code structure.

    This is only a small part of a solution. Its ‘usefulness’ is by building the dictionary first, the command line interface is decoupled from the code. Then refactoring the code should be easier, in a test-driven development sense, because the tests and cronjobs won’t have to change as the underlying code is restructured. It gives the flexibility to do the restructuring in an iterative and piecemeal way.

    (From the comments, it looks like folks knows how to use a dictionary do this).

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

Sidebar

Related Questions

I have a class defined like this, with the appropriate getter and setter methods...
I have: @Component class MyDecorator{ private Cache cache; /* some wrapped methods like get
Let's say we have a memory-intensive class like an Image , with chainable methods
I have a Log class that has several static methods which help log information
How often should I use static methods generally? If I have like: Class1 _class34
I have a proxied method in a MongoRepository extender class like this: public interface
I have an abstract method in a base class declared like so... public abstract
I have a class MyClass, and I would like to override the method ToString()
I have a class like this: class MyClass{ public: MyClass(int Mode); private: std::map <
I have a class like this public class foo { private void getThread() {

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.