[Zope] Python script and dtml-with

Farrell, Troy troy.farrell@wilcom.com
Wed, 28 Feb 2001 14:31:27 -0600


Muchos Gracias Evan.
It makes a bunch more sense now.

Troy

-----Original Message-----
From: Evan Simpson [mailto:evan@4-am.com]
Sent: Wednesday, February 28, 2001 2:05 PM
To: Farrell, Troy; zope@zope.org
Subject: Re: [Zope] Python script and dtml-with


From: Farrell, Troy <troy.farrell@wilcom.com>
> I'm not explicitly having a problem, but I would like an explanation.  I
> understand the usefullness of dtml-with in dtml.  I was converting some
dtml
> methods to python scripts and I ran across a dtml-with.  Is there an
> equivalent for python scripts?  If so, great.  If not, please explain why
it
> is not needed.  Thanks in advance.

"dtml-with" is a tool for putting names on the namespace stack, which is
critical for DTML, since the namespace stack is the source of all names.
Python, on the other hand, doesn't use DTML namespaces, although it can
manipulate them like any other data structure.  It doesn't need them, since
it can easily create a local variable.  Example:

<dtml-with expr="foo.bar.controller()"><dtml-var x><dtml-var y></dtml-with>

This really means "put 'foo.bar.controller()' on the namespace stack, ask
the namespace stack for 'x' and 'y', then pop the stack, but the person who
wrote it was probably thinking "get 'x' and 'y' from foo.bar.controller()".
In this case, the following Python works:

fbc = foo.bar.controller()
print fbc.x
print fbc.y

Cheers,

Evan @ digicool & 4-am