Parsing Python code with a Python Program

Discussion in 'Python' started by pgw, Aug 23, 2004.

  1. pgw

    pgw Guest

    Hello,

    I would like to pass strings to a Python
    application and have them executed as though
    they were lines of code.

    Is 'exec()' the function that I am looking for
    and/or is there an example of this somewhere?

    Thanks,

    Seaweed
     
    pgw, Aug 23, 2004
    #1
    1. Advertising

  2. pgw

    pw Guest

    Hello,

    I had my quotes wrong is all.

    EXAMPLE:

    exec 'print "Hello"'

    OR:

    s = 'print "hello"'

    exec s

    Thanks anyway,

    Seaweed






    pgw wrote:
    > Hello,
    >
    > I would like to pass strings to a Python
    > application and have them executed as though
    > they were lines of code.
    >
    > Is 'exec()' the function that I am looking for
    > and/or is there an example of this somewhere?
    >
    > Thanks,
    >
    > Seaweed
    >
     
    pw, Aug 23, 2004
    #2
    1. Advertising

  3. pgw <> writes:

    > Hello,
    >
    > I would like to pass strings to a Python
    > application and have them executed as though
    > they were lines of code.
    >
    > Is 'exec()' the function that I am looking for
    > and/or is there an example of this somewhere?


    Well, it's a statement, not a function, but yes, that's what you're
    looking for.

    Cheers,
    mwh

    --
    Well, you pretty much need Microsoft stuff to get misbehaviours
    bad enough to actually tear the time-space continuum. Luckily
    for you, MS Internet Explorer is available for Solaris.
    -- Calle Dybedahl, alt.sysadmin.recovery
     
    Michael Hudson, Aug 23, 2004
    #3
  4. pgw

    Ivo Woltring Guest

    Well you can also generate code into a specific file name and then import
    the file and execute the generated code by reference to file.function...

    goodluck
    Ivo

    "Michael Hudson" <> wrote in message
    news:...
    > pgw <> writes:
    >
    > > Hello,
    > >
    > > I would like to pass strings to a Python
    > > application and have them executed as though
    > > they were lines of code.
    > >
    > > Is 'exec()' the function that I am looking for
    > > and/or is there an example of this somewhere?

    >
    > Well, it's a statement, not a function, but yes, that's what you're
    > looking for.
    >
    > Cheers,
    > mwh
    >
    > --
    > Well, you pretty much need Microsoft stuff to get misbehaviours
    > bad enough to actually tear the time-space continuum. Luckily
    > for you, MS Internet Explorer is available for Solaris.
    > -- Calle Dybedahl, alt.sysadmin.recovery
     
    Ivo Woltring, Oct 22, 2004
    #4
    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. GIMME
    Replies:
    2
    Views:
    895
    GIMME
    Feb 11, 2004
  2. Naren
    Replies:
    0
    Views:
    592
    Naren
    May 11, 2004
  3. Christopher Diggins
    Replies:
    0
    Views:
    619
    Christopher Diggins
    Jul 9, 2007
  4. Christopher Diggins
    Replies:
    0
    Views:
    446
    Christopher Diggins
    Jul 9, 2007
  5. len
    Replies:
    8
    Views:
    286
Loading...

Share This Page