473,379 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

execute python code from db

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.
Jul 18 '05 #1
3 2003
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
Jul 18 '05 #2
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 | nc******@email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
Jul 18 '05 #3
> for python_code in c.fetchall():
execute (python_code)

Maybe feed python with stdin??.


eval

--
damjan
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sheila King | last post by:
I have searched for an answer to this question on the comp.lang.python archives at Google Groups, and also looked through the (sparse) MySQLdb documentation, and cannot confirm for a FACT what I...
2
by: Tim Williams | last post by:
I'm trying to write a simple python program to access a MySQL database. I'm having a problem with using MySQLdb to get the results of a SQL command in a cursor. Sometimes the cursor.execute works,...
19
by: citronelu | last post by:
Is it possible to execute a binary string stored within a python script as executable code ? The script is run under Windows, and the binary code (a full executable file) is stored in a variable...
2
by: stef | last post by:
hello, doing a simulation of another language (JAL), I translate the other language into Python code, then I execute this converted Python code. Now I need todo some checks and give visual...
5
by: johnny | last post by:
Anyone know how I can make Machine A python script execute a python script on Machine B ?
3
by: joe jacob | last post by:
I configured apache to execute python scripts using mod_python handler. I followed below mentioned steps to configure apache. 1. In http.conf I added <Directory...
5
by: nimitsis | last post by:
Hello to everyone I wont to create 2 threads in Python ( thread01, thread02 ), which doing the follows : thread01, ask user to give a value to flag variable and write it to the shared memory of...
0
by: David | last post by:
- Are there any peculiarities with using curs.executemany(...) vs. multiple How many times are you calling execute vs a single executemany? The python call overhead will add up for thousands of...
7
by: ChaosKCW | last post by:
Hi I am trying to use pymssql, and have an issue where by the execute (not the fetch) is appearing to load all records into memory. if I execute con = pymssql.connect(...) cur =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.