[Zope] Newbie in python script
Dieter Maurer
dieter@handshake.de
Fri, 11 Apr 2003 22:20:31 +0200
CY wrote at 2003-4-11 12:32 +0800:
> I would like to know how-to extract results variable from a python script.
> The python script will extract and parse the string into y, m, d variables.
> How do I pass these variables into dtml method?
>
> TQ
>
> Python script
> =========
> parameter = yearmonthdate
>
> ymd=string.split(yearmonthday,"/")
> y=ymd[0]
> m=ymd[1]
> d=ymd[2]
> return y, m, d
You return a tuple.
You can access the components of a tuple with subscription
syntax: "tuple[i]".
As Andreas suggested, you can bind values to names with
"dtml-let" and reuse them several times.
<dtml-let
date="splitDate(...)"
y="date[0]"
m="date[1]"
d="date[2]"
>
....
</dtml-let>
It may be easier to return a dictionary and use
<dtml-with "splitDate(...)" mapping>
<dtml-var y>
</dtml-with>
Dieter