Hi will these be possible? <tal:b tal:define='dictionary python: {"value1": ["one", "two", "three"], "value2": "two", "value3": "three"}'> <tal:b tal:replace='python: dictionary["value1"][5] | "Value not available"' /> </tal:b> Obviously these is an incorrect tal expression (the replace one) but there are any way to create an expression like these and correct? Thank you!!!
--On Donnerstag, 4. November 2004 9:09 Uhr +0100 Garito <garito@sistes.net> wrote:
Hi will these be possible?
<tal:b tal:define='dictionary python: {"value1": ["one", "two", "three"], "value2": "two", "value3": "three"}'> <tal:b tal:replace='python: dictionary["value1"][5] | "Value not available"' /> </tal:b>
Obviously these is an incorrect tal expression (the replace one) but there are any way to create an expression like these and correct?
Please look at the Python Dictionary API, especially the has_key() or get() method. -aj
Andreas Jung wrote:
--On Donnerstag, 4. November 2004 9:09 Uhr +0100 Garito <garito@sistes.net> wrote:
Hi will these be possible?
<tal:b tal:define='dictionary python: {"value1": ["one", "two", "three"], "value2": "two", "value3": "three"}'> <tal:b tal:replace='python: dictionary["value1"][5] | "Value not available"' /> </tal:b>
Obviously these is an incorrect tal expression (the replace one) but there are any way to create an expression like these and correct?
Please look at the Python Dictionary API, especially the has_key() or get() method.
-aj
Hi Andreas (Good morning!) Thank you for your light speed response ;) The get() method would be fantastic but my problem is with the list I know that value1 exists in the dictionary but I don't know the length of the list It would be perfect if I have some get method (with default value like dictionary's get) for the list Another possibility will be some if sentence like expresion ? result for true : result for false Has python these kind of if? Any idea?
Garito wrote:
Andreas Jung wrote:
--On Donnerstag, 4. November 2004 9:09 Uhr +0100 Garito <garito@sistes.net> wrote:
Hi will these be possible?
<tal:b tal:define='dictionary python: {"value1": ["one", "two", "three"], "value2": "two", "value3": "three"}'> <tal:b tal:replace='python: dictionary["value1"][5] | "Value not available"' /> </tal:b>
Obviously these is an incorrect tal expression (the replace one) but there are any way to create an expression like these and correct?
Please look at the Python Dictionary API, especially the has_key() or get() method.
-aj
Hi Andreas (Good morning!) Thank you for your light speed response ;) The get() method would be fantastic but my problem is with the list I know that value1 exists in the dictionary but I don't know the length of the list It would be perfect if I have some get method (with default value like dictionary's get) for the list
Another possibility will be some if sentence like expresion ? result for true : result for false Has python these kind of if?
Any idea?
Put the tal:replace-part in a python script, Parameters mdict, mkey idx, msg: try: return mdict.get(mkey,[])[idx] except IndexError: return msg Untested! HTH, Wolfram
On Thu, 2004-11-04 at 09:34, Garito wrote:
Andreas Jung wrote:
--On Donnerstag, 4. November 2004 9:09 Uhr +0100 Garito <garito@sistes.net> wrote:
Hi will these be possible?
<tal:b tal:define='dictionary python: {"value1": ["one", "two", "three"], "value2": "two", "value3": "three"}'> <tal:b tal:replace='python: dictionary["value1"][5] | "Value not available"' /> </tal:b>
Obviously these is an incorrect tal expression (the replace one) but there are any way to create an expression like these and correct?
Please look at the Python Dictionary API, especially the has_key() or get() method.
-aj
Hi Andreas (Good morning!) Thank you for your light speed response ;) The get() method would be fantastic but my problem is with the list I know that value1 exists in the dictionary but I don't know the length of the list It would be perfect if I have some get method (with default value like dictionary's get) for the list
Another possibility will be some if sentence like expresion ? result for true : result for false Has python these kind of if?
I always recomend skimming thru the python tutorial to get an idea of what you can do with python. Armed with a python interpreter started interactively you have all the tools you can use later with development to actually try out. I would also like to ask if this is already production code. E.g. are the values really defined this way in the template? If you later use "something" to produce this data structure, consider doing all the logic and evaluation there too. To answer your true and false, python in 2.3 (Zope2.7) has True and False as real boolean types. In Expressions, 0,"",'',[],{} and so on are considered False too. This is used a lot. Hint: if you use strings as keys in your dictionary, you could use path expressions. If you have a list, iterate over it rather then trying to access it directly via list index. Regards Tino
On Thu, 04 Nov 2004 10:08:23 +0100, Tino Wildenhain <tino@wildenhain.de> wrote: <snip>
To answer your true and false, python in 2.3 (Zope2.7) has True and False as real boolean types. In Expressions, 0,"",'',[],{} and so on are considered False too. This is used a lot.
Hint: if you use strings as keys in your dictionary, you could use path expressions. If you have a list, iterate over it rather then trying to access it directly via list index.
hi tino could you elaborate a bit/point me to docs on this? i would have think that getting it via index would be cheaper/faster ? thanks
Regards Tino
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- http://myzope.kedai.com.my - my-zope.org
Hi Use can write something like this to get the length of the list for a key <span tal:replace="python: len(dictionary.get(key, []))" /> If there is no entry for the "key" in the dictionary en empty list is returned. Hope this will help Garito wrote:
Andreas Jung wrote:
--On Donnerstag, 4. November 2004 9:09 Uhr +0100 Garito <garito@sistes.net> wrote:
Hi will these be possible?
<tal:b tal:define='dictionary python: {"value1": ["one", "two", "three"], "value2": "two", "value3": "three"}'> <tal:b tal:replace='python: dictionary["value1"][5] | "Value not available"' /> </tal:b>
Obviously these is an incorrect tal expression (the replace one) but there are any way to create an expression like these and correct?
Please look at the Python Dictionary API, especially the has_key() or get() method.
-aj
Hi Andreas (Good morning!) Thank you for your light speed response ;) The get() method would be fantastic but my problem is with the list I know that value1 exists in the dictionary but I don't know the length of the list It would be perfect if I have some get method (with default value like dictionary's get) for the list
Another possibility will be some if sentence like expresion ? result for true : result for false Has python these kind of if?
Any idea?
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Dragos Chirila Programmer, Finsiel ROMANIA 44A, Ficusului St. - 71544 Bucharest Tel: +40 21 2320193 Fax: +40 21 2329807 URL: http://www.finsiel.ro Jabber: dragos@jabber.finsiel.ro
Garito wrote:
Hi will these be possible?
<tal:b tal:define='dictionary python: {"value1": ["one", "two", "three"], "value2": "two", "value3": "three"}'> <tal:b tal:replace='python: dictionary["value1"][5] | "Value not available"' /> </tal:b>
Obviously these is an incorrect tal expression (the replace one) but there are any way to create an expression like these and correct?
You can use the TAL "on-error" handler: <tal:b tal:replace="python: dictionary['value1'][5]" tal:on-error="string:Value not available" /> see also your TAL online help: http://localhost:8080/Control_Panel/Products/PageTemplates/Help/tal-on-error... Michael -- http://zope.org/Members/d2m
Garito wrote:
Hi will these be possible?
<tal:b tal:define='dictionary python: {"value1": ["one", "two", "three"], "value2": "two", "value3": "three"}'> <tal:b tal:replace='python: dictionary["value1"][5] | "Value not available"' /> </tal:b>
Obviously these is an incorrect tal expression (the replace one) but there are any way to create an expression like these and correct?
Thank you!!!
Now I have a correct expression (thanks to Chema Cortés from spanish zope list). This is the expression: (len(dictionary['value1'])>6 and dictionary['value1'][5]) or 'Value not available' Thanks for all your help!!!
Hi, On Thu, 2004-11-04 at 09:57, Garito wrote:
Garito wrote:
Hi will these be possible?
<tal:b tal:define='dictionary python: {"value1": ["one", "two", "three"], "value2": "two", "value3": "three"}'> <tal:b tal:replace='python: dictionary["value1"][5] | "Value not available"' /> </tal:b>
Obviously these is an incorrect tal expression (the replace one) but there are any way to create an expression like these and correct?
Thank you!!!
Now I have a correct expression (thanks to Chema Cortés from spanish zope list). This is the expression:
(len(dictionary['value1'])>6 and dictionary['value1'][5]) or 'Value not available'
Just for the records: (dictionary.get('value',[])[5:]+['Value not available'])[0] is the functional programming approach to this problem. Regards Tino
Garito wrote:
Hi will these be possible?
<tal:b tal:define='dictionary python: {"value1": ["one", "two", "three"], "value2": "two", "value3": "three"}'> <tal:b tal:replace='python: dictionary["value1"][5] | "Value not available"' /> </tal:b>
Obviously these is an incorrect tal expression (the replace one) but there are any way to create an expression like these and correct?
Thank you!!!
Now I have a correct expression (thanks to Chema Cortés from spanish zope list). This is the expression:
(len(dictionary['value1'])>6 and dictionary['value1'][5]) or 'Value not available'
Thanks for all your help!!!
An alternative that should work (although it is untested): <tal:b replace="dictionary/value1/5|string:Value not available" />
Duncan Booth wrote:
Garito wrote:
Hi will these be possible?
<tal:b tal:define='dictionary python: {"value1": ["one", "two", "three"], "value2": "two", "value3": "three"}'> <tal:b tal:replace='python: dictionary["value1"][5] | "Value not available"' /> </tal:b>
Obviously these is an incorrect tal expression (the replace one) but there are any way to create an expression like these and correct?
Thank you!!!
Now I have a correct expression (thanks to Chema Cortés from spanish zope list). This is the expression:
(len(dictionary['value1'])>6 and dictionary['value1'][5]) or 'Value not available'
Thanks for all your help!!!
An alternative that should work (although it is untested):
<tal:b replace="dictionary/value1/5|string:Value not available" />
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Sorry but your solution doesn't work (Value not available in all cases) I think these work with an array like: {"value1": {"1": "One", "2": "Two", "5": "Five"}} But thanks!
participants (8)
-
Andreas Jung -
Bakhtiar A Hamid -
Dragos Chirila -
Duncan Booth -
Garito -
Michael Haubenwallner -
Tino Wildenhain -
Wolfram Kraus