execute python code from db

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • robert

    #1

    execute python code from db

    Hello,

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

    db=MySQLdb.conn ect(host="local host",user="r", passwd="j",db=" v")

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

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

    Maybe feed python with stdin??.


    robert.
  • Laszlo Zsolt Nagy

    #2
    Re: execute python code from db

    robert wrote:
    [color=blue]
    >Hello,
    >
    >Anybody knows if it's possible to execute python code from an db.
    >
    >db=MySQLdb.con nect(host="loca lhost",user="r" ,passwd="j",db= "v")
    >
    >c=db.cursor( )
    >c.execute("""S ELECT * FROM table
    > WHERE id = %s""", (id,))
    >
    >for python_code in c.fetchall():
    > execute (python_code)
    >
    >Maybe feed python with stdin??.
    >
    >[/color]



    Look for these:

    compile
    exec
    eval
    execfile

    Also the statement exec:



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

    Best,

    Laci 2.0


    Comment

    • Nick Coghlan

      #3
      Re: execute python code from db

      robert wrote:[color=blue]
      > Hello,
      >
      > Anybody knows if it's possible to execute python code from an db.
      >
      > db=MySQLdb.conn ect(host="local host",user="r", passwd="j",db=" v")
      >
      > c=db.cursor()
      > c.execute("""SE LECT * FROM table
      > WHERE id = %s""", (id,))
      >
      > for python_code in c.fetchall():
      > execute (python_code)
      >
      > Maybe feed python with stdin??.[/color]

      What's wrong with the exec statement?

      Cheers,
      Nick.

      --
      Nick Coghlan | ncoghlan@email. com | Brisbane, Australia
      ---------------------------------------------------------------

      Comment

      • Damjan

        #4
        Re: execute python code from db

        > for python_code in c.fetchall():[color=blue]
        > execute (python_code)
        >
        > Maybe feed python with stdin??.[/color]

        eval

        --
        damjan

        Comment

        Working...