Newbie Question!

Gerhard Häring gerhard.nospam at
Tue Aug 7 02:01:52 CEST 2001

On Mon, 06 Aug 2001 20:51:36 -0000, ksunair at <ksunair at> wrote:
>I am new to Python and interested to develop a new website using only 
>Python. I would like to know, few things
>1. Is there a simple example out there to print 'Hello World' on web?
>like the one in PHP
><html><body><?php echo 'hello World' ?> </body></html>

#!/usr/bin/env python
print "Content-type: text/html\n"
print "<html><body>hello World</body></html>"

The above is an equivalent Python cgi script.

>2. Is there a tutorial or documentation available anywhere on the 
>net, how to use MySql with Python?

The closest thing is the DB-API documentation (MySQLdb is an implementation of
the DB-API). You can find the docs on -> Docs -> Topic Guides ->
Database - I'm too lazy to check it in my browser now :-)

The mySQLdb module contains some examples, but I'm not aware of an all-beginner
tutorial, the docs suppose you're already fairly familiar with SQL.

Basically it works like this:

import MySQLdb          # or whatever other PostgrSQL/Oracle/... module

# Open database connection
con = MySQLdb.connect( host = "dbserver", user = "me", passwd = "secret" )

# Get a cursor object
cur = con.cursor()

# Make a select/insert/update
cursor.execute( "select * from test where id>50" )

# In case of a select, fetch the results and do something with them
print cursor.fetchall()


mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:              public key at homepage
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y: x+y, [chr(ord(x)^42) for x in list('zS^BED\nX_FOY\x0b')])

More information about the Python-list mailing list