basic python -> dtml translation.
trivial no doubt, but buggered if i can find the python equivalent for "eval". eg. how would you rewrite this in dtml : for i in range(1,6) : print (eval('var%s' % i)) which prints out the values of var1, var2, var3, var4, var5, var6 <dtml-in "_.range(1,6)"> ?? </dtml-in> cheers, chas
chas wrote:
trivial no doubt, but buggered if i can find the python equivalent for "eval". eg. how would you rewrite this in dtml :
for i in range(1,6) : print (eval('var%s' % i))
<dtml-in "_.range(1,6)"> <dtml-var "_['var'+_['sequence-item']]"> </dtml-in> or, since you're a PythonMethods fan, for i in range(1,6): print _['var%s' % i] Thanks for the kudos, by the way. As for the use of tabs in PythonMethod code, my advice is: DON'T. Hit the spacebar 2 or 4 times instead; you'll be glad you did. FTP only works for FTP-enabled classes, which AFAIK only includes DTML objects. Patches are welcome, of course <wink>.
trivial no doubt, but buggered if i can find the python equivalent for "eval". eg. how would you rewrite this in dtml :
for i in range(1,6) : print (eval('var%s' % i))
<dtml-in "_.range(1,6)"> <dtml-var "_['var'+_['sequence-item']]"> </dtml-in>
or, since you're a PythonMethods fan,
for i in range(1,6): print _['var%s' % i]
Thanks for the help - this second snippet is nice and concise and I think demonstrates the power of PythonMethods : (1) using Python as the framework whilst being able to call Zope objects and (2) greater readability of code ... although I may be a little biased there <g>. Btw, I'd just like to clarify my earlier comments : DTML is OK perhaps for content authors/teams so I was not meaning to rag on it. But I've accomplished more in the past 6 hours than in the previous 4 days by moving all logic to PythonMethods and feel MUCH better about building apps now.
Thanks for the kudos, by the way. As for the use of tabs in PythonMethod code, my advice is: DON'T. Hit the spacebar 2 or 4 times instead; you'll be glad you did.
Cool. Did I miss a technote on this ? Coming from Python, others might assume that tabs are needed. cheers, chas
chas wrote:
Thanks for the kudos, by the way. As for the use of tabs in PythonMethod code, my advice is: DON'T. Hit the spacebar 2 or 4 times instead; you'll be glad you did.
Cool. Did I miss a technote on this ? Coming from Python, others might assume that tabs are needed.
But tabs aren't needed in Python -- you can use spaces just fine in Python (as long as you don't *mix* spaces with tabs). Spaces tend to be easier on portability as everybody seems to have different ideas about how large a tab should be. Regards, Martijn
participants (3)
-
chas -
Evan Simpson -
Martijn Faassen