[Zope] int's as keys for dictionaries

James Henderson james at logicalprogression.net
Wed May 26 13:04:06 EDT 2004


On Wednesday 26 May 2004 5:53 pm, Bryce Harrington wrote:
> On Wed, 26 May 2004, Ben Last (Zope) wrote:
> > > Bryce Harrington
> > >
> > > > > <dtml-let d_test_parameter="{'1':'a', '2':'b'}">
> > >
> > > Yes, that is correct.  The data structure has strings, but I need to
> > > access them using ints as keys.  So I have to convert the ints into
> > > strings in order to retrieve the data.
> >
> > So why not init with
> > d_test_parameter="{1:'a', 2:'b'}
> > ...so that your keys are ints from the beginning?
>
> Zope is converting them to strings on form submission.
>
> Bryce

Hi Bryce,

Did you know that you can convert values directly to ints by adding ":int" to 
the value of the "name" atribute in the form element, e.g.:

<input name="smtp_port:int" />

This works for other types too.  See a concise explanation in section 2.6.3 of 
Dieter Maurer's book:

http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html#ZPublisher

HTH,
James
-- 
James Henderson, Logical Progression Ltd.
http://www.logicalprogression.net/
http://sourceforge.net/projects/mailmanager/




More information about the Zope mailing list