On Wed, 19 Jan 2005 01:32:47 +0100, Marcin Krol <[EMAIL PROTECTED]> wrote:
> I'm actually somewhat disappointed by Python interface to MK. I thought I
> would be able to access MK view as if it were a list of lists or list
> of dictionaries, not via the 'RowRef' objects with dot access,
Back in the day, I felt like you that this aspect of metakit was
cumbersome, but I finally came to realize the power of the rowref. If
you had the dictionary approach, every element of the row would have
to be accessed and converted.
for row in view:
print row.a
Only the 'a' attribute is ever used and retrieved. Furthermore, since
metakit is column oriented, the column is sequential in memory/disk
making access tremendously fast. Now, if you find the value of a that
you like, then you can access the other columns.
Now, if you are just
> However, in the following statement: like
> ViewName.PropertyName and iterating over view or doing
> find(name='Joe'). I'd prefer smth more resembling typical operation of
> Python's list/dicts. An ideal would be IMHO smth like:
>
> a={'joe':['doe', 44], 'john': ['lennon', 45], 'joe': ['smith', 42]}
>
> ..but implemented in such a way that a user could access any column as
> a key, smth a la multi-way dictionary, so user could specify
>
> a[(0, 'joe')]
You are, of course, free to implement this functionality, python is
very dynamic in this regard, but should this throw an exception if the
key doesn't exist like a dictionary? What if you multiple values that
match (0,'joe')? If there is one should it return an object and for
many should it return a list?
You can certainly convert a view into a set of dictionaries, but
remember that in the metakit world, the underlying view can change
*underneath* you. Columns can be removed, rows can be deleted and the
row reference will *still* work!
>
> I'm sure implementing smth like this
> would be a lot of work, though.
Ask and ye shall receive. The following is a metakit wrapper that
wraps metakit calls. There may be bugs in it so beware. It behaves
just like metakit except:
import mkwrap
st = mkwrap.storage()
vw = st.getas(...)
vw[0,'a'] -> retrieves column 'a' at row 0, equivalent to vw[0].a
vw.asDict() -> returns lists of internal dictionaries
row.asDict() -> converts the row to a dictionary.
Enjoy
mkwrap.py
Description: Binary data
_____________________________________________ Metakit mailing list - [email protected] http://www.equi4.com/mailman/listinfo/metakit
