[ZPT] Using variables in path expressions

Evan Simpson evan@digicool.com
Fri, 8 Jun 2001 00:04:04 -0400


From: "Brent M Hendricks" <brent@valinor.waldenweb.com>
> Hmm.  Is there a technical reason why it uses a different syntax here?
> In the interest of consistency, I'd think we would want to use ${} here
> too.

There's a subtle difference between string interpolation and path
interpolation that we wanted to highlight with differing syntax.  In path
interpolation, you split the path at the slashes, then replace '?x'
elements.  Thus, "here/?name" is always a two-element path and will fail to
resolve if 'name' is 'a/b', even if "here/a/b" exists. To resolve, 'name'
would need to be ['a', 'b']. Also, the element must start with the question
mark in order to be interpolated, so "a/x?b/c" will not cause path
interpolation.

This feature was never fully baked, which is why it's undocumented.

> And since I'm already nagging you about notation (<grin>), I might as
> well ask: How hard would it be to allow paths embedded in paths?  I
> would think you could just pass the expression through the "string:"
> processor first to expand the variables and then pass the resultant
> string into the "path:" processor.

As a matter of fact, you can do just that in a Python expression, at least
three ways:

python:path(string('a/${x/y}/c'))
python:path('a/%s/c' % path('x/y'))
python:path('a/' + path('x/y') + '/c')

Cheers,

Evan @ digicool