Calling multiple methods of an object in sequence

gnicki

I need to do something like this:

abc = xyz()
abc.method1()
abc.method2()
abc.method3()
...

Is there a way to shorten this? Like:

abc= xyz()
abc.{method1(),method2(),method3(),...}

or something?

Lancelot du Lac

You can do this by ensuring that the instance functions (methods) each return a reference to the instance in which they are running (self)

class xyz:
    def method1(self):
        print('m1')
        return self
    def method2(self):
        print('m2')
        return self
    def method3(self):
        print('m3')
        return self

abc = xyz()
abc.method1().method2().method3()

Output:

m1
m2
m3

Observation:

Whilst it can be done, I offer this merely as an answer to the original question. I do not condone the practice

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Clojure: calling a sequence of methods on a Java object

From Dev

Calling multiple methods for one object simultaneously?

From Dev

Calling multiple methods on same same object without any references

From Dev

Calling object methods in Javascript

From Java

Calling multiple methods in Java

From Dev

Calling multiple methods on a variable

From Dev

Test of the sequence of calling of some methods of a Python class

From Dev

Call list of methods on object in sequence, piping the methods?

From Dev

Testing multiple methods calling order

From Dev

WSO2 EI/ESB - Calling multiple endpoints in sequence to generate a custom object

From Java

Calling methods on reference variable vs Calling methods on a new object

From Java

Calling object methods within Arrays.reduce(...)

From Java

Shortcut for calling all the setter methods on an object in Eclipse?

From Dev

Is there any Design Pattern for calling object methods statically

From Dev

Calling external methods without instantiating an object

From Dev

Best practice when calling self object methods

From Dev

Return type annotation for calling an object's methods

From Dev

Calling methods of actual object instead of parent class

From Dev

calling methods using object reference variable

From Dev

Calling multiple methods with ng-click Angularjs

From Dev

Angular 2 calling multiple async methods

From Dev

Casting an object in an Array vs ArrayList and calling methods on the object

From Dev

Calling multiple bash scripts and running them in parallel, not in sequence

From Dev

Calling multiple API in sequence using RxJava,Retrofit,RxKotlin flatmap

From Dev

An object calling multiple of functions with the correct overload set

From Dev

Calling multiple nested object recursively giving undefined

From Dev

Calling methods on object gets 'call to member function on array' error

From Java

Does calling @Bean methods create a new instance of the object or the bean instance?

From Dev

Calling member methods from class object in python 3

Related Related

  1. 1

    Clojure: calling a sequence of methods on a Java object

  2. 2

    Calling multiple methods for one object simultaneously?

  3. 3

    Calling multiple methods on same same object without any references

  4. 4

    Calling object methods in Javascript

  5. 5

    Calling multiple methods in Java

  6. 6

    Calling multiple methods on a variable

  7. 7

    Test of the sequence of calling of some methods of a Python class

  8. 8

    Call list of methods on object in sequence, piping the methods?

  9. 9

    Testing multiple methods calling order

  10. 10

    WSO2 EI/ESB - Calling multiple endpoints in sequence to generate a custom object

  11. 11

    Calling methods on reference variable vs Calling methods on a new object

  12. 12

    Calling object methods within Arrays.reduce(...)

  13. 13

    Shortcut for calling all the setter methods on an object in Eclipse?

  14. 14

    Is there any Design Pattern for calling object methods statically

  15. 15

    Calling external methods without instantiating an object

  16. 16

    Best practice when calling self object methods

  17. 17

    Return type annotation for calling an object's methods

  18. 18

    Calling methods of actual object instead of parent class

  19. 19

    calling methods using object reference variable

  20. 20

    Calling multiple methods with ng-click Angularjs

  21. 21

    Angular 2 calling multiple async methods

  22. 22

    Casting an object in an Array vs ArrayList and calling methods on the object

  23. 23

    Calling multiple bash scripts and running them in parallel, not in sequence

  24. 24

    Calling multiple API in sequence using RxJava,Retrofit,RxKotlin flatmap

  25. 25

    An object calling multiple of functions with the correct overload set

  26. 26

    Calling multiple nested object recursively giving undefined

  27. 27

    Calling methods on object gets 'call to member function on array' error

  28. 28

    Does calling @Bean methods create a new instance of the object or the bean instance?

  29. 29

    Calling member methods from class object in python 3

HotTag

Archive