[Zope] Tricky usage of string to integer conversion

Thomas Weiner weiner@tu-harburg.de
Tue, 07 Mar 2000 15:18:40 +0100


"Brian K. Holdsworth" schrieb:
> 
> I am trying to do the following:
> 
> <dtml-let x:int="REQUEST.get('prod_config')"
>           item="_[REQUEST.get('prod_id')]"
>           price="item.price_list[x]">
>     <INPUT type="hidden" name="chargetotal" value="<dtml-var price>">
> </dtml-let>
> 
> The prod_config variable is a number (returned as a string) from a SELECT
> list.  The prod_id variable is the id of an object in the same folder as
> this method that has a price_list attribute.  price_list is a list of
> strings representing prices.
> 
> This results in a "Name Error" where Zope cannot find "x".  If I change line
> 3 to this:
> 
>           price="item.price_list['x']">
> 
> it fixes the Name Error, but then I get a "Sequence Index must be an
> integer" error on price_list['x'].  I would have thought the use of "x:int"
> in my <dtml-let> would take care of this issue.  Seems I can't win!
>
> Does anyone know the correct way to do this lookup?

I think it must be converted by the atoi method of the string module:

so either:

<dtml-let x="_.string.atoi(REQUEST.get('prod_config'))" 
          [rest of your code]
or:

<dtml-let x="REQUEST.get('prod_config')"
           item="_[REQUEST.get('prod_id')]"
           price="item.price_list[_.string.atoi(x)]">
          
hth,
Thomas