0

I have the following code:

def myfunction(con, command, options=None):
    if options != None:
        return getattr(con, command)(options)

returnvalue = myfunction(fromcon, 'search', (None, 'all'))

I need to change it so that it does the same thing as:

returnvalue = getattr(fromcon, 'search')(None, 'all')

Help.

malana
  • 5,045
  • 3
  • 28
  • 41
asc
  • 1

1 Answers1

2

You want the *args syntax:

def myfunction(con,command,options=None):
    if options is not None:
        return getattr(con,command)(*options)

returnvalue = myfunction(fromcon,'search',(None,'all'))

You can read more about how this works here

Community
  • 1
  • 1
lemonhead
  • 5,328
  • 1
  • 13
  • 25
  • Hah, that seems to have done it. Just have to change all my other options to (mystring,) and it doesn't divide them into letters. Thanks. – asc Jul 27 '15 at 22:27