[Tutor] database programming
misha.dunn at gmail.com
Mon Feb 21 15:22:54 CET 2005
If you just want to learn about databases, then sqlite is a good way
to go. It's small, it's typeless (which means you don't have to define
ahead of time what sort of thing is going to go in which bit of the
database; python is typeless too), and it is not split into client and
server (making it much simpler to install and manage, although you
can't use it for fancy stuff over a network).
You can install sqlite from http://www.sqlite.org/ if you want to play
around with the interpreter. This is a good idea if you're not used to
databases or you don't know sql, because then you'll learn better what
python is trying to do (or what you're trying to make python do).
There are plenty of one-off jobs that are easier to do directly in the
sqlite interpreter too.
To use sqlite from python you need pysqlite from
http://sourceforge.net/projects/pysqlite. If you install the binary
you don't need to install sqlite separately.
There are simple examples of usage in the manual (at
http://pysqlite.org/manual.html, or with the installation files). A
short example is:
connection = sqlite.connect("my_database") # make a connection
cursor = connection.cursor() # make a database cursor
cursor.execute("select * from table1") # send a sql command to the database
results = cursor.fetchall() # get a list with the results
On Mon, 21 Feb 2005 18:42:22 +0800, Chris Mallari <cvmallari at gmail.com> wrote:
> hi there! can u pls send me sample code in accessing a simple database
> using python.
> Chris Mallari
> Tutor maillist - Tutor at python.org
More information about the Tutor