Dictionary type access to list of instances

Brian Kelley bkelley at wi.mit.edu
Tue Feb 26 09:15:51 EST 2002

Grant Beasley wrote:

> What I'm ultimately aiming for is a database-like view of a list of
> instances, so that I can use SQL commands to get instances. So in the
> analogy, a list of instances would be a table, with each instance a record,
> and each property a field.
> eg.
> class User:
>     def __init__(self, username, accesslevel):
>         self.username = username
>         self.accesslevel = accesslevel
> list = [User('Bob', 1), User('Jim', 2), User('Pete', 2)]
> Then using my imaginary function ListSQL:
> ListSQL("select * from list where accesslevel = 2")
> would return a list consisting of the Jim and Pete instances.
> or ListSQL("select username, accesslevel from list where accesslevel = 2")
> would return [('Jim', 2), ('Pete',2)] - i.e. a List of tuples.

> Is this an interesting / useful idea? Has it been done before? Any comments?

You might want to check out database objects 

or gadly, a python relational database

I have had a great deal of success with metakit which I endorse heavily

and I willing to bet Zope has a solution in this realm as well...

These might help from not reinventing the wheel.

Brian Kelley

More information about the Python-list mailing list