Hi,

Speaking of ordered dictionary :

http://www.voidspace.org.uk/python/weblog/arch_d7_2005_11_19.shtml#e140

Why is the ordering so important ? I do understand we need to support
multiple values per field name, but I don't see why ordering is
needed.

Regards,
Nicolas

2005/11/28, David Fraser <[EMAIL PROTECTED]>:
> Gregory (Grisha) Trubetskoy wrote:
>
> >
> >
> > Having looked at the FieldStorage code, I'm guessing the idea was that
> > you parse fields as they come in and append them to a list. This
> > preserves the original order of fields, in case it is needed.
> >
> > I'm not sure that maintaining a dictionary alongside the list is the
> > right thing to do. It might be, but there are some difficult questions
> > to answer -e.g. how costly is a sequential search, and is the code
> > complexity (and fieldstorage code is no picnic to read as it is) worth
> > the speedup?
> >
> > Also while it would speed up retrieval, it will slow down the "write"
> > operation - when a field is added to fieldstorage you now need to
> > append it to the list, AND check whether it exists in the dictionary,
> > then add it there as well.
> >
> > How often do developers access form fields via __getitem__?  I noticed
> > the publisher does not use it - it iterates the list, so nothing would
> > be gained there.
>
> We do it a lot but we copy it into a different dictionary first to get
> exactly the setup we want. But dictionary-style access is a very
> obvious, pythonic way to do it.
> I have a simple 70-line ordereddict implementation which is derived from
> dict and remembers the keys in the order that they were assigned when
> iterating through the list, this may be a way to go for this. It just
> uses a list of keys internally to remember the order, and otherwise is a
> dictionary...
>
> > Also, something else to consider - is there a simple programatic
> > solution that could be documented, e.g. something like
> >
> > my_fs = util.FieldStorage(req)
> >
> > dict_fs = {}
> > dict_fs.update(my_fs)
> >
> > [have no idea whether this will work :-)]
>
> It may work but still has the potential performance problem since it
> loops through the keys and then does a getitem on each key which loops
> through them again. Not likely to cause problems for a small number of
> arguments but not ideal :-)
>
> > and voila - you've got a dictionary based fieldstorage?
> >
> > Anyway, just a few cents from me.
> >
> > Grisha
> >
>
>

Reply via email to