1

I wants to send extra arguments to another function, is this the right way to do that.

def foo(self, request, method='post', page=None,**options):
    #do something
    self.another_foo(options)

def another_foo(self, data=None):
    print data

self.foo(5,data="free")
user87005
  • 964
  • 3
  • 10
  • 27
  • That depends on what that other function expects to receive. – bereal Jun 02 '15 at 09:43
  • Please add more details on the aim of the function and what you want to achieve. Also do they need to be named arguments? – NDevox Jun 02 '15 at 09:45
  • updated the question, I want to use data in another_foo. – user87005 Jun 02 '15 at 09:49
  • Why don't you try it, and see? As written, `data` in `another_foo` will be *the dictionary* (`{'data': 'free'}`). If instead you want `data` in `another_foo` to be `'free'`, then you need to use `self.another_foo(**options)` - see http://stackoverflow.com/q/36901/3001761 – jonrsharpe Jun 02 '15 at 09:51
  • Do you want the extra arguments to appear in the function as a tuple (positional) or as a dictionary (keyword arguments)? – cdarke Jun 02 '15 at 09:52

1 Answers1

4

You pass it using **-notation, the same way as you receive it:

def foo(self, request, method='post', page=None, **options):
    #do something
    self.another_foo(**options)
bereal
  • 32,519
  • 6
  • 58
  • 104