Calling functions with dynamic arguments

Discussion in 'Python' started by SeanDavis12, Nov 29, 2006.

  1. SeanDavis12

    SeanDavis12 Guest

    I have a dictionary like:

    {"a":1, "b":2}

    and I want to call a function:

    def func1(a=3,b=4):
    print a,b

    so that I get a=1,b=2, how can I go about that?

    Thanks,
    Sean
     
    SeanDavis12, Nov 29, 2006
    #1
    1. Advertising

  2. SeanDavis12 wrote:
    > I have a dictionary like:
    >
    > {"a":1, "b":2}
    >
    > and I want to call a function:
    >
    > def func1(a=3,b=4):
    > print a,b
    >
    > so that I get a=1,b=2, how can I go about that?


    func1(**yourdict)

    --
    Roberto Bonvallet
     
    Roberto Bonvallet, Nov 29, 2006
    #2
    1. Advertising

  3. SeanDavis12

    SeanDavis12 Guest

    Roberto Bonvallet wrote:
    > SeanDavis12 wrote:
    > > I have a dictionary like:
    > >
    > > {"a":1, "b":2}
    > >
    > > and I want to call a function:
    > >
    > > def func1(a=3,b=4):
    > > print a,b
    > >
    > > so that I get a=1,b=2, how can I go about that?

    >
    > func1(**yourdict)


    Thanks, Roberto.

    Sean
     
    SeanDavis12, Nov 29, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Vallstrom
    Replies:
    2
    Views:
    2,040
    Kevin Bracey
    Nov 21, 2003
  2. S?ren Gammelmark
    Replies:
    1
    Views:
    1,984
    Eric Sosman
    Jan 7, 2005
  3. Navaneeth
    Replies:
    4
    Views:
    573
    Kenny McCormack
    Nov 20, 2010
  4. Tyler
    Replies:
    2
    Views:
    107
    Tyler
    May 22, 2006
  5. oldyork90
    Replies:
    10
    Views:
    368
    Jorge
    Sep 27, 2008
Loading...

Share This Page