Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > execute python code from db

Reply
Thread Tools

execute python code from db

 
 
robert
Guest
Posts: n/a
 
      01-26-2005
Hello,

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

db=MySQLdb.connect(host="localhost",user="r",passw d="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.
 
Reply With Quote
 
 
 
 
Laszlo Zsolt Nagy
Guest
Posts: n/a
 
      01-26-2005
robert wrote:

>Hello,
>
>Anybody knows if it's possible to execute python code from an db.
>
>db=MySQLdb.connect(host="localhost",user="r",pass wd="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


 
Reply With Quote
 
 
 
 
Nick Coghlan
Guest
Posts: n/a
 
      01-26-2005
robert wrote:
> Hello,
>
> Anybody knows if it's possible to execute python code from an db.
>
> db=MySQLdb.connect(host="localhost",user="r",passw d="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
 
Reply With Quote
 
Damjan
Guest
Posts: n/a
 
      01-26-2005
> for python_code in c.fetchall():
> execute (python_code)
>
> Maybe feed python with stdin??.


eval

--
damjan
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to execute Python code from C++ without writing toa file? Roger House Python 1 04-16-2011 12:01 PM
Execute C code through Python Ernesto Python 14 10-26-2005 02:44 PM
How to Execute Code Behind Code in Inline aspx Kamal Ahmed ASP .Net 1 10-25-2005 08:09 AM
execute python code and save the stdout as a string jwaixs Python 2 06-27-2005 04:29 PM
Can i execute aspx file in my asp pag with server.execute method(sorry) Savas Ates ASP General 1 08-17-2004 04:52 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57