Python and MySQL

Status
Not open for further replies.
Posted by Me in Linux Kung Fu-
Howdy-
I'm considering doing a project in Python.

Its a php web application for folding@home user stats but the database will need to be updated four times a day from a script running in the crontab.

I want to use Python for that.

Know of any good sites dealing with Python and MySQL?

Posted by jemfinch-
If it's going to be part of the same application as you've already written in PHP, why not write the script you need in PHP?

Aside from that, this belongs in the programming forum. I'm locking it, sorry smile

Jeremy

So- here it is :)
 
jemfinch-

the reason I don't want to use php from the crontab is because I only build the apache dso, not the php binary that is used for cgi-bin or cli php programming.

I don't really have a desire to build the php standalone binary either.

What I want to use python for is to fetch new data from the web four times a day and populate the new info into the database.

That's a cron job.
I could have cron access a php programmed web page via lynx- but why, when I can have python do it w/o going through the web server?
 
I tried building this module-

http://www.bel-epa.com/pyapache/Python/MySQL-python/

MySQL 3.23.49 (I tried 3.23.43 as well on Linux)
Python 2.2.1 installed in /usr/local

Build fails in same way on both Linux and OS X-

running build_ext
building '_mysql' extension
cc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -no-cpp-precomp -I/usr/local/include/mysql -I/usr/local/include/python2.2 -c _mysqlmodule.c -o build/temp.darwin-5.4-Power Macintosh-2.2/_mysqlmodule.o
_mysqlmodule.c: In function `_mysql_ResultObject_fetch_row':
_mysqlmodule.c:943: too many arguments to function `_PyTuple_Resize'
error: command 'cc' failed with exit status 1
[osx:local/src/MySQL-python-0.3.0] michael%

(same problem in Linux)

Any ideas?
 
http://www.zope.org/Members/adustman/Products/MySQLdb

It's got a much newer version- 0.90
but alas- identical compile error- just different line number :(

building '_mysql' extension
creating build/temp.darwin-5.4-Power Macintosh-2.2
cc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -no-cpp-precomp -I/usr/local/include/mysql -I/usr/local/include/python2.2 -c _mysql.c -o build/temp.darwin-5.4-Power Macintosh-2.2/_mysql.o
_mysql.c: In function `_mysql__fetch_row':
_mysql.c:784: too many arguments to function `_PyTuple_Resize'
error: command 'cc' failed with exit status 1
[osx:local/src/MySQL-python-0.9.0] michael%
 
Coolness, I thought maybe you would have gone to SourceForge first...

I got a Python project assignment today. My boss wants a way to automate testing some Intranet software. No budget, no time alloted, has to be infinitly adaptable, yadda, yadda, yadda...

So I'm thinking a proxy server written in Python could record a session between a browser and a web site. So time to dig around in the books and such...

q
 
Yeah- this is my first "Python Project" myself.

What I'm doing I could easily do in Perl or even bourne- it's not that much, just downloading tab deliminated text files and updating a database table based upon the contents of the text files.

But I've been wanting to learn Python and this seems like a good way to do so (I do much better at learning something if I have a purpose in mind)
 
But I've been wanting to learn Python and this seems like a good way to do so (I do much better at learning something if I have a purpose in mind)

Only way to learn a language is to do projects in it. I have a bunch of real silly programs and some scripts I did to try various aspects of Python and some real large projects to that force me to learn the whole language.

1) Satellite orbit calculator, rebuilding the vector classes on that. This project started off to be a port of some Pascal code, but I'm forced to refactor the modules and learn the stuff. Scary. I haven't messed with "real" math since the university. This project taught me Python classes.

2) Python/Tk code for controlling various stuff attached to a serial port. There's a PySerial module out there that I want to try.

3) Proxy server. All other projects including building radios go to the back of the line for this. If completed, could be extra bonus money at the end of the year. ;)

q
 
I'm not going to argue postgresql vs MySQL

I'm not going to run more than one database on this machine and I already have stuff that doesn't yet have postgresql equivalents (though they are being worked on) using the MySQL database.

As such, since I've already got MySQL running, there is no need to install another database.

Both MySQL and PostGre are good open source databases.
I don't need transaction support- so I really don't see a reason to switch databases.

Also- you'll find MySQL is a lot more readily available on server farms, http://www.he.net/ for example.

Database holy wars aside for this- MySQL is what I got and it's in use already with other stuff.
 
Quality - didn't we talk a few weeks ago about vector
class stuff for that orbital program?

Like I said, it taught me classes. :D

I learned that you can't cram every thing into a class, some functions just need to be on their own. But the module is done except the built-in tests, my programming mentor drilled that into my head.

BTW, it's not a clean re-usable vector classes that you could use outside of this application. I basically stuck with Dr. Kelso's data type, which is specialized for this type of work. It would require rewriting entire app from scratch, and if I did that, there is a newish book out with some nice gcc code that I would use instead. Which defeats the whole purpose of the project, which is to learn Python at a deeper level.

Anywho that's on the back burner for now. I'm working through some of the networking examples in Lutz's book for the proxy server project. Also found some source code on the 'net I might poke at. There are some cool serious uses for this stuff. :)

q
 

sonic

Ars Scholae Palatinae
954
Yeah- this is my first "Python Project" myself.
SQL was the reason I learned Python at all. I had a look at some code snippets for dealing with databases.. I almost had a heart attack after looking at Perl, so Python it was

What I'm doing I could easily do in Perl or even bourne- it's not that much, just downloading tab deliminated text files and updating a database table based upon the contents of the text files.
The hardest part of learning it (for me) was figuring out what functions are called. Download the Python documentation, you'll be grepping through it rather heavily :)
 
Status
Not open for further replies.