> That is a surprise to me.  I did not know that Python would work with
SQLite.   

Sure, as someone else said, Python comes with a LOT of libraries built right
in when you download Python.  This is known as "batteries included", that is,
what comes with the standard distribution of Python.  

> I will look into Alan's tutorial on DB. 

It is of course thorough and will really provide understanding.  But just to
emphasize how simple creating a SQLite database in Python is, I recommend
you do these 4 simple steps:

1. Download and install the very nice SQLite Database Browser application, 
from here:
http://sourceforge.net/projects/sqlitebrowser/

It's simple and good.  

2. Now open IDLE (which also comes with Python), do File > New Window,
and paste this simple Python code into that window:

#--------------------------------------
#get SQLite into Python...it's that simple!
import sqlite3

#Make a connection to a database...if it doesn't exist yet, we'll create it.
conn = sqlite3.connect('my_database.db')   

#Create a "cursor", a kind of "pen" that writes into the database.
cur = conn.cursor()

#Write a table, called here MyTable, into the database, and give it two fields,
# name and address.
cur.execute('''CREATE TABLE if not exists MyTable (name, address)''')

#Now actually write some data into the table you made:
cur.execute('INSERT INTO MyTable VALUES(?,?)',('John','Chicago'))

#Always have to commit any changes--or they don't "stick"!
conn.commit()

#You're done!
#------------------------------------------

Without the comments, (which explain a bit about why it is written
as it is) this is just this small an amount of Python code--6 lines:

import sqlite3

conn = sqlite3.connect('my_database.db')   

cur = conn.cursor()

cur.execute('''CREATE TABLE if not exists MyTable (name, address)''')

cur.execute('INSERT INTO MyTable VALUES(?,?)',('John','Chicago'))

conn.commit()


3. Run your program in IDLE (Run > Run Module...or just hit F5).  Save
it to your Desktop.

4. Now view your handiwork in the SQLite Database Browser.  Open
it and then do File > Open Database, then find a file on your Desktop
called mydatabase.db.  Open it.  Now you are looking at the database
you just made.  Click on the Browse Data tab and you are now seeing
that John lives in Chicago.

It's that simple to at least get started.  Thanks, Python.

Che










 I am getting more
and more surprised of what Python can do.  Very comprehensive.   Thanks
all.




Ken 
                                          
_________________________________________________________________
Bing brings you maps, menus, and reviews organized in one place.
http://www.bing.com/search?q=restaurants&form=MFESRP&publ=WLHMTAG&crea=TEXT_MFESRP_Local_MapsMenu_Resturants_1x1
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to