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. Advertisements

  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. Advertisements

  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. Advertisements

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. Xiangliang Meng
    Replies:
    1
    Views:
    1,917
    Victor Bazarov
    Jun 21, 2004
  2. Daniel Vallstrom
    Replies:
    2
    Views:
    2,860
    Kevin Bracey
    Nov 21, 2003
  3. Edward Diener
    Replies:
    14
    Views:
    5,954
    Josiah Carlson
    Apr 6, 2004
  4. S?ren Gammelmark
    Replies:
    1
    Views:
    2,248
    Eric Sosman
    Jan 7, 2005
  5. Ross A. Finlayson
    Replies:
    19
    Views:
    832
    Keith Thompson
    Mar 10, 2005
  6. Navaneeth
    Replies:
    4
    Views:
    742
    Kenny McCormack
    Nov 20, 2010
  7. Tyler
    Replies:
    2
    Views:
    164
    Tyler
    May 22, 2006
  8. oldyork90
    Replies:
    10
    Views:
    603
    Jorge
    Sep 27, 2008
Loading...