0

If I have a function:

def run(time, message, time_span_pattern):
    ...

And a list like:

run_args = ['1s', '1 second alarm', <_sre.SRE_Pattern object at 0x100435680>]

How can I pass the list, as separate arguments, to run? Is there a builtin way to do this, or am I forced to reference each element individually and by index?

theonlygusti
  • 9,142
  • 8
  • 49
  • 93
  • note, that is not a valid list because <_sre.sre_pattern at="" object=""> is not a valid identifer. But if it had been all you need is run(*run_args) – e4c5 Jan 06 '17 at 07:49
  • 1
    http://stackoverflow.com/questions/36901/what-does-double-star-and-star-do-for-parameters – Łukasz Rogalski Jan 06 '17 at 07:49
  • @e4c5 why does it work in the REPL? – theonlygusti Jan 06 '17 at 07:50
  • @ŁukaszRogalski yeah but that question is about how to make a function which accepts multiple arguments, not about how to pass a list into one. – theonlygusti Jan 06 '17 at 07:53
  • 1
    Possible duplicate of [Pass elements of a list as arguments to a function in python](http://stackoverflow.com/questions/2756116/pass-elements-of-a-list-as-arguments-to-a-function-in-python) – DYZ Jan 06 '17 at 08:04

1 Answers1

3

You're looking for:

run(*run_args)

This is explained in more detail in this StackOverflow answer about the star and double star operator

It's also covered in the python docs

Community
  • 1
  • 1
ffledgling
  • 10,464
  • 8
  • 43
  • 66