Skip to main content
added 440 characters in body
Source Link
Martijn Pieters
  • 1.1m
  • 325
  • 4.2k
  • 3.4k

More, better options:

  1. Add **kwargs to your functions and ignore extra arguments:

     ex_method(arg1, arg2, **kw)
    
  2. Pass around an object with all arguments as attributes; a namedtuple class would be ideal here. Each function only uses those attributes it needs.

I'd pick the latter. Stop moving around 10 arguments, start passing around just one.

Even better, if all those operations are really coupled to the data those arguments represent, perhaps you should be using a class instead:

class SomeConcept(object):
    def __init__(self, arg1, arg2, arg3, .., argN):
        self.arg1 = arg1
        # ... etc.

    def operation1(self, external_argument):
        # use `self` attributes, return something.

instead of all those separate functions.

More, better options:

  1. Add **kwargs to your functions and ignore extra arguments:

     ex_method(arg1, arg2, **kw)
    
  2. Pass around an object with all arguments as attributes; a namedtuple class would be ideal here. Each function only uses those attributes it needs.

I'd pick the latter. Stop moving around 10 arguments, start passing around just one.

More, better options:

  1. Add **kwargs to your functions and ignore extra arguments:

     ex_method(arg1, arg2, **kw)
    
  2. Pass around an object with all arguments as attributes; a namedtuple class would be ideal here. Each function only uses those attributes it needs.

I'd pick the latter. Stop moving around 10 arguments, start passing around just one.

Even better, if all those operations are really coupled to the data those arguments represent, perhaps you should be using a class instead:

class SomeConcept(object):
    def __init__(self, arg1, arg2, arg3, .., argN):
        self.arg1 = arg1
        # ... etc.

    def operation1(self, external_argument):
        # use `self` attributes, return something.

instead of all those separate functions.

Source Link
Martijn Pieters
  • 1.1m
  • 325
  • 4.2k
  • 3.4k

More, better options:

  1. Add **kwargs to your functions and ignore extra arguments:

     ex_method(arg1, arg2, **kw)
    
  2. Pass around an object with all arguments as attributes; a namedtuple class would be ideal here. Each function only uses those attributes it needs.

I'd pick the latter. Stop moving around 10 arguments, start passing around just one.