[Zope] Re: Zope digest, Vol 1 #633 - 67 msgs

Tres Seaver tseaver@palladion.com
Wed, 16 Feb 2000 12:52:15 -0600


"Christopher J. Kucera" <ckucera@globalcrossing.com> wrote:
> To: zope@zope.org
> Subject: [Zope] Behavior of <dtml-let>
> 
> I discovered an interesting attribute of <dtml-let> after it was
> biting me on the nose for awhile.  I've got a property, "db_Columns",
> of type "lines."  In my code, I do the following:
> 
>   <dtml-let columns="db_Columns">
>      ...
>     <dtml-call "columns.append('blahblahblah')">
>      ...
>   </dtml-let>
> 
> The append works wonderfully for my "local" variable columns, but
> as it turns out, it also appends 'blahblahblah' to "db_Columns".
> 
> I totally understand why this happens, and it certainly makes sense
> for <dtml-let> to function this way; I just thought that some mention
> of this feature in the DTML Reference guide (or some such document)
> could save someone else the trouble of tracking down why a screen is
> rendering very oddly.

Hmm, let + mutable objects....  To avoid the problem, I'd try::

  <dtml-let columns="db_Columns[:]">

which should "clone" the list, instead of merely binding another name to it. 
Mutable "global" objects (lists, dictionaries, maybe instances?) inside DTML (or
PythonMethods) are kind of a gnarly problem.

Tres.
-- 
=========================================================
Tres Seaver         tseaver@palladion.com    713-523-6582
Palladion Software  http://www.palladion.com