'IN' Atribute within as a python script parameter
Im having some trouble trying to pass a atribute to a python script: <dtml-in objectValues> <dtml-var "pythonScript(sequence-length)"> -- I dont know how I can make it understand the 'sequence-item' as a parameter </dtml-in> Thanks one more time for the help! Alexandre Aguiar
Alexandre Aguiar wrote:
Im having some trouble trying to pass a atribute to a python script:
<dtml-in objectValues> <dtml-var "pythonScript(sequence-length)"> -- I dont know how I can make it understand the 'sequence-item' as a parameter </dtml-in>
Thanks one more time for the help!
Alexandre Aguiar
You do realize that the above would call the pythonScript once for each item in the list right? if that's not what you want try: <dtml-var expr="pyScript(_.len(objectIds())"> if so then: <dtml-in objectValues> <dtml-var "pythonScript(_['sequence-length'])"> </dtml-in> any names with Python-significant characters (such as "." or "-") must be escapes using _[] in expressions. hth, -- | Casey Duncan | Kaivo, Inc. | cduncan@kaivo.com `------------------>
Im having some trouble trying to pass a atribute to a python script:
<dtml-in objectValues> <dtml-var "pythonScript(sequence-length)"> -- I dont know how I can make it understand the 'sequence-item' as a parameter </dtml-in>
Thanks one more time for the help!
Due to the naming of the dtml-in variables, Python thinks you're trying to do subtraction when you say 'sequence-item' or so in an expression. You need to use one of:: _['sequence-item'] or:: <dtml-let sl=sequence-length> <dtml-var "pythonScript(sl)"> </dtml-let> --jcc (questionable)
Hi Alexandre, --On Montag, 13. August 2001 17:29 -0300 Alexandre Aguiar <ale@thecook.org> wrote:
Im having some trouble trying to pass a atribute to a python script:
<dtml-in objectValues> <dtml-var "pythonScript(sequence-length)"> -- I dont know how I can make it understand the 'sequence-item' as a parameter </dtml-in>
Both sequence-item and sequence-length have hypenations in the name which becomes in a python expression a subtraction. You either have to use _['sequence-item'] ( I think your sequence-length is a typo) or <dtml-let si=sequence-item> <dtml-var "pythonScript(si)"></dtml-with> But I dont think this is a good idea anyway. If you use pythonscripts, you dont need to do the loop in DTML. Just put it all in the pythonscript: for item in context.objectValues(): do something with the values If you really want only the length, you would use len(context.objectIds()) Not that objectIds is faster and saves memory if you only want to count the objects. Regards Tino
Thanks one more time for the help!
Alexandre Aguiar
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
You either have to use _['sequence-item'] ( I think your sequence-length is a typo) or <dtml-let si=sequence-item> <dtml-var "pythonScript(si)"></dtml-with>
However be careful, be *very* careful, when using _['sequence-item'] or <dtml-let si=sequence-item>, because in the not so infrequent case where sequence-item is an object that is callable, like, say, a DTML Document, it will get called, thus rendered, and "si" will be a string and not an object like you probably expected...
But I dont think this is a good idea anyway. If you use pythonscripts, you dont need to do the loop in DTML. Just put it all in the pythonscript:
Agreed. Florent Guillaume Nuxeo
However be careful, be *very* careful, when using _['sequence-item'] or <dtml-let si=sequence-item>, because in the not so infrequent case where sequence-item is an object that is callable, like, say, a DTML Document, it will get called, thus rendered, and "si" will be a string and not an object like you probably expected...
By the way I failed to mention, you might want to use instead: _.getitem('sequence-item') which doesn't call the object. See Dieter's very nice doc at: http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html#Object_argume... Florent Guillaume Nuxeo
participants (5)
-
Alexandre Aguiar -
Casey Duncan -
Florent Guillaume -
J. Cameron Cooper -
Tino Wildenhain