[Zope] What If i don't want Zope sorting for me.

Terry terry@taipeitimes.com
Tue, 26 Feb 2002 10:18:17 +0800


Hi  friend,

I tried a Python Script
### Python Script
context.REQUEST.set('my_dic',{
'ar_id':'Article ID',
'ar_head':'Head',
'ar_sbhdtease':'Sub Head Tease',
'ar_sbhdbody':'Sub Head Body',
'ar_byline':'By line',
'ar_body':'Body'})
print context.REQUEST.my_dic.keys()
return printed
### End of Python Script

The script return
#######

['ar_sbhdtease', 'ar_sbhdbody', 'ar_body', 'ar_id', 'ar_head', 'ar_byline']

#######
It just forget the original order I just defined. Any idea ?

Terry






Chris Withers wrote:

>>Terry wrote:
>>
>>I have a dictionary in REQUEST.
>>
>><dtml-call "REQUEST.set('my_dic',{'ar_id':'Article
>>ID','ar_head':'Head','ar_body':'Body'})">
>><dtml-var "my_dic.keys()">
>>
>>Zope will sort for me. How to use the original order ?
>>
>
>1. Don't use DTML for that kindof code, it's nasty. Use a Script (Python)
>instead.
>
>the above would be:
>
>context.REQUEST.set('my_dict',
>                    {
>                      'ar_id'  :'Aticle ID',
>                      'ar_head':'Head',
>                      'ar_body':'Body'})
>return REQUEST.my_dict.keys()
>
>As for the sorting, Zope sorts nothing. Python Dictionaries don't promise to
>order their keys so you may get them back in any random order.
>
>cheers,
>
>Chris
>
>PS: HTML to a non-HTML list is also a no-no. Stop usign Outlook Express before
>it kills you ;-)
>
>