Best way to inplace alter a list going into postgres

Ben Finney ben+python at benfinney.id.au
Tue May 31 00:54:02 EDT 2016


Sayth Renshaw <flebber.crue at gmail.com> writes:

> What is the best way to inplace alter a list going into a postgres
> database using split but being sure that the order of items remains
> correct.

That's a trick question. The best way to modify fields of a record is
not with a list.

Instead, you should get the record in the form of a mapping (such as
Python's built-in mapping type, ‘dict’) and alter the fields *by name*.

Ony when it's time to serialise the data should you then convert it to a
list, extracting by the sequence of field names (‘horseattrs’ in your
example).

-- 
 \       “Firmness in decision is often merely a form of stupidity. It |
  `\        indicates an inability to think the same thing out twice.” |
_o__)                                                —Henry L. Mencken |
Ben Finney




More information about the Python-list mailing list