Database interfacing
Michael T. Babcock
mbabcock at fibrespeed.net
Fri Jan 9 10:45:06 EST 2004
I'm working with databases (MySQL primarily) more and more with Python,
and having used PERL in the past for similar work, I'm wondering if
there are good tools for doing 'intelligent' selects/inserts to/from
dictionaries, etc. For example:
data = {'FirstName': 'Michael', 'LastName': 'Babcock', 'Age': 99}
lastid = db.insert('Users', data)
... which would execute "INSERT INTO Users (FirstName, LastName, Age)
VALUES ('Michael', 'Babcock', 99)"
And also helpful would be:
data = db.query("dbname", "SELECT * FROM Users WHERE Age >= 99)")
... which would return me an array of dictionary items like:
[ {'ID': 143, 'FirstName': 'Michael' ... }, {'ID': 242, ... }, ... ]
Just curious, thanks (I've written a piece of code to generate the array
of dictionary results myself actually, but I'm sure someone else's is
better).
--
Michael T. Babcock
C.T.O., FibreSpeed Ltd.
http://www.fibrespeed.net/~mbabcock
More information about the Python-list
mailing list