Python good for data mining?

Cameron Walsh cameron.walsh at
Sun Nov 4 15:00:46 CET 2007

Jens wrote:
> Thanks a lot! I'm not sure I completely understand your description of
> how to integrate Python with, say PHP. Could you please give a small
> example? I have no experience with Python web development using CGI.
> How easy is it compared to web development in PHP?
> I still havent't made my mind up about the choice of programming
> language for my data mining project. I think it's a difficult
> decision. My heart tells me "Python" and my head tells me "Java" :-)

My C++ lecturer used to tell us "'C++ or Java?' is never the question. 
For that matter, Java is never the answer."

As for python and cgi, it's pretty simple.  Instead of a .php file to be 
handled by the php-handler, you have a .cgi file which is handled by the 
cgi-handler.  Set the action of your html form to the .cgi file.  At the 
top of the .cgi file, you'll need a line like:

#!/usr/bin/env python

Which tells it to use python as the interpreter.  You'll need a few imports:

import cgi
import cgitb; cgitb.enable() # for debugging - it htmlises
			     # your exceptions and error messages.
print """Content-type: text/html; charset="iso-8859-1";\n"""
# You need that line or something similar so the browser knows what to 
do with the output of the script.

Everything that's printed by the python script goes straight to the 
client's browser, so the script will have to print html.  The cgi module 
handles form data, typically formdata = cgi.FieldStorage() will be 
filled when a form is sent to the script.  print it and see what's in it.

 From here, there's a huge number of tutorials on python and cgi on the 
web and I'm tired.

Best of luck,


More information about the Python-list mailing list