What's the neatest way of getting dictionary entries in a specified order?

Chris Green cl at isbd.net
Wed Mar 8 15:28:07 EST 2017


Jussi Piitulainen <jussi.piitulainen at helsinki.fi> wrote:
> Chris Green writes:
> 
> > I have a fairly simple application that populates a GUI window with
> > fields from a database table.  The fields are defined/configured by a
> > dictionary as follows:-
> >
> >     # 
> >     # 
> >     # Address Book field details, dictionary key is the database column 
> >     # 
> >     dbcol = {}
> >     dbcol['firstname'] = col('First Name', True, False)
> >     dbcol['lastname'] = col('Last Name', True, False)
> >     dbcol['email'] = col('E-Mail', True, True)
> >     dbcol['phone'] = col('Phone', True, True)
> >     dbcol['mobile'] = col('Mobile', True, True)
> >     dbcol['address'] = col('Address', True, False)
> >     dbcol['town'] = col('Town/City', True, False)
> >     dbcol['county'] = col('County/Region', True, False)
> >     dbcol['postcode'] = col('PostCode', True, False)
> >     dbcol['country'] = col('Country', True, False)
> >     dbcol['notes'] = col('Notes', True, False)
> >     dbcol['www'] = col('Web Page', True, True)
> >     dbcol['categories'] = col('Categories', True, True)
> >
> > How can I get the fields in the GUI window in the order I want rather
> > than the fairly random order that they appear in at the moment?
> 
> Look up OrderedDict in the collections module.

Thanks, that's what I need.

-- 
Chris Green
·



More information about the Python-list mailing list