1

I'm working on an project where I have defined a lot of functions in my code. I just have a doubt, if it is possible to put all these functions inside a single function and just call this single function in main.

class Project:
    def login(self):
        #code
    def upload(self):
        #code
    def import(self):
        #code

if __name__ == '__main__':
    c=Project()
    c.login()
    c.upload()
    c.import()

So, my doubt is , is it possible to include all the methods inside a single method and call only one method in the main which triggers all the methods. Thanks!

2
  • You can certainly do that. However, Andrew's approach is lot cleaner if you have too many of these functions. Commented Feb 6, 2018 at 5:53
  • Yep i will try ! Commented Feb 6, 2018 at 5:57

1 Answer 1

3

Try something like this:

class Project:
    def login(self):
        #code
    def upload(self):
        #code
    def import(self):
        #code
    def do_all(self):
        self.login()
        self.upload()
        self.import()

if __name__ == '__main__':
    c=Project()
    c.do_all()
Sign up to request clarification or add additional context in comments.

1 Comment

Since you have only methods on your class, you might consider simply defining the functions at the module level. Then you can call do_all() without instantiating an object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.