questions about exec...

Discussion in 'Python' started by Hoesl, Feb 9, 2010.

  1. Hoesl

    Hoesl

    Joined:
    Feb 9, 2010
    Messages:
    1
    Hi...I am new to programming, I'm trying out all kind of stuff and it is fun.
    I just have this question about python..

    x = "g = lambda x,y: x+y"
    exec(x)
    g(1,2) <----that will give me number 3.

    f = "g(1,2)"
    answer = exec "f"


    why will this give me a syntax error? is there ways to assign "g(1,2)" as code not as string so I can execute it?
     
    Hoesl, Feb 9, 2010
    #1
    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. Hal Vaughan
    Replies:
    11
    Views:
    1,195
    Gordon Beaton
    May 22, 2006
  2. tedsuzman
    Replies:
    2
    Views:
    7,164
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  3. Ted
    Replies:
    1
    Views:
    494
    Duncan Booth
    Jul 22, 2004
  4. Guillermo Riojas
    Replies:
    0
    Views:
    198
    Guillermo Riojas
    Nov 26, 2010
  5. Random Task
    Replies:
    12
    Views:
    725
    Joe Smith
    Dec 4, 2005
Loading...

Share This Page