execute python code from db

Discussion in 'Python' started by robert, Jan 26, 2005.

  1. robert

    robert Guest

    Hello,

    Anybody knows if it's possible to execute python code from an db.

    db=MySQLdb.connect(host="localhost",user="r",passwd="j",db="v")

    c=db.cursor()
    c.execute("""SELECT * FROM table
    WHERE id = %s""", (id,))

    for python_code in c.fetchall():
    execute (python_code)

    Maybe feed python with stdin??.


    robert.
     
    robert, Jan 26, 2005
    #1
    1. Advertising

  2. robert wrote:

    >Hello,
    >
    >Anybody knows if it's possible to execute python code from an db.
    >
    >db=MySQLdb.connect(host="localhost",user="r",passwd="j",db="v")
    >
    >c=db.cursor()
    >c.execute("""SELECT * FROM table
    > WHERE id = %s""", (id,))
    >
    >for python_code in c.fetchall():
    > execute (python_code)
    >
    >Maybe feed python with stdin??.
    >
    >


    http://docs.python.org/lib/built-in-funcs.html

    Look for these:

    compile
    exec
    eval
    execfile

    Also the statement exec:

    http://docs.python.org/ref/exec.html#l2h-562

    I also recommend to look at the documentation of "global","globals"
    before you try to use them.

    Best,

    Laci 2.0
     
    Laszlo Zsolt Nagy, Jan 26, 2005
    #2
    1. Advertising

  3. robert

    Nick Coghlan Guest

    robert wrote:
    > Hello,
    >
    > Anybody knows if it's possible to execute python code from an db.
    >
    > db=MySQLdb.connect(host="localhost",user="r",passwd="j",db="v")
    >
    > c=db.cursor()
    > c.execute("""SELECT * FROM table
    > WHERE id = %s""", (id,))
    >
    > for python_code in c.fetchall():
    > execute (python_code)
    >
    > Maybe feed python with stdin??.


    What's wrong with the exec statement?

    Cheers,
    Nick.

    --
    Nick Coghlan | | Brisbane, Australia
    ---------------------------------------------------------------
    http://boredomandlaziness.skystorm.net
     
    Nick Coghlan, Jan 26, 2005
    #3
  4. robert

    Damjan Guest

    > for python_code in c.fetchall():
    > execute (python_code)
    >
    > Maybe feed python with stdin??.


    eval

    --
    damjan
     
    Damjan, Jan 26, 2005
    #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. Kamal Ahmed
    Replies:
    1
    Views:
    5,243
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=
    Oct 25, 2005
  2. jwaixs
    Replies:
    2
    Views:
    977
    jwaixs
    Jun 27, 2005
  3. Ernesto

    Execute C code through Python

    Ernesto, Oct 20, 2005, in forum: Python
    Replies:
    14
    Views:
    9,260
    Ernesto
    Oct 26, 2005
  4. Roger House
    Replies:
    1
    Views:
    255
    Anssi Saari
    Apr 16, 2011
  5. Savas Ates
    Replies:
    1
    Views:
    299
    Patrice
    Aug 17, 2004
Loading...

Share This Page