This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Display for OrderedDict
Type: enhancement Stage:
Components: Versions: Python 3.1
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, georg.brandl, rhettinger, tweiler
Priority: normal Keywords:

Created on 2009-03-27 14:54 by tweiler, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
od_sample.py tweiler, 2009-04-06 21:30 Example using OrderDict for UI
Messages (5)
msg84261 - (view) Author: Todd Weiler (tweiler) Date: 2009-03-27 14:54
Now that python has an ordered dictionary it would be great to have a
display sytax for creating them.

To create a dict I just use the dict display syntax:
newdict = {'fred':'flintstone', 'barney':'rubble', 'dino':'thedinosaur'}

I'd like to be able to create an OrderedDict in the same way - I realize
that a list of tuples would do the trick, but I find the dict display
more convenient and readable.  Back in the archives there is probably a
whole discussion of why dict displays are useful.  My reason for liking
displays is that I like to put dictionaries inside dictionaries - the
display format spread out over several lines makes this easy to read.

Possible solutions:

1. maybe use ^{ for OrderedDicts
newdict = ^{'fred':'flintstone', 'barney':'rubble', 'dino':'thedinosaur'}

2. have OrdredDict accept a dictionary display string
newodict = OrderedDict("{'fred':'flintstone', 'barney':'rubble',
'dino':'thedinosaur'}"}
msg85485 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-04-05 11:49
I don't think this is going to fly -- 1. because we don't lightly add
new syntax for every data type and 2. because it doesn't scale beyond
simple keys and values.  A list of tuples is explicit and works fine.
msg85669 - (view) Author: Todd Weiler (tweiler) Date: 2009-04-06 21:30
Let me defend my idea a little bit.

Some people hand code their UI's, some people put them into XML UI files
then load those files.

I'd like to create them using an OrderedDict.  I'm using the pyQT for a gui.

Attached is a really simple example program that creates little window
that doesn't really do anything except set up the interface.  Note the
use of a dictionary to set up the interface.  The OrderedDict is more
concise than XML, is Python Code not a separate file and easy to read.

This was inspired by the "builder" concept in Groovy.

Thanks for your time.
msg85675 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-04-06 22:23
The proposal for a custom syntax has nearly zero chance of success.

FWIW, the JSON module provides an alternative way to get a the same
result using the new object_pairs_hook (being added to Py2.7 and Py3.1).
msg85677 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-04-06 23:43
For this usage I'd suggest a class.
See http://www.python.org/dev/peps/pep-3115/ the example 
containing "OrderedClass".
With a little work, your code could look like:

class Interface(TabbedPane):
   class FirstTab(Pane):
        label = 'First Tab'
        LineEdit('First Name', length=20)
        LineEdit('Last Name', length=30)
        ComboBox('Title', length=10,
                 list=['Mr', 'Mrs', 'Ms', 'Dr', 'BDFL'])
   class SecondTab(Pane):
        label = 'Second Tab'
        LineEdit('City', length=20)
        LineEdit('Street', length=30)
History
Date User Action Args
2022-04-11 14:56:47adminsetgithub: 49829
2009-04-06 23:43:37amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg85677
2009-04-06 22:23:41rhettingersetnosy: + rhettinger
messages: + msg85675
2009-04-06 21:30:24tweilersetfiles: + od_sample.py

messages: + msg85669
2009-04-05 11:49:16georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg85485

resolution: rejected
2009-03-27 14:54:18tweilercreate