Database interfacing
George Young
gee_arr_why at ll.mit.edu
Fri Jan 9 15:12:45 EST 2004
On Fri, 09 Jan 2004 10:45:06 -0500, Michael T. Babcock wrote:
> 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).
You might find dbrow helpful:
http://opensource.theopalgroup.com/
http://opensource.theopalgroup.com/files/db_row-0.8.tgz
http://opensource.theopalgroup.com/files/db_row.py
--
George Young
gee arr why at ll.mit.edu
[three letter username]
More information about the Python-list
mailing list