execute python code from db

R

robert

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

Laszlo Zsolt Nagy

robert said:
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
 
N

Nick Coghlan

robert said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top