calling an Python builtin function
Hi Zopistas, it's a pain looking to variables defined in a form such as checkboxes that can be a string if one is selected or a sequence if many are. to solve this problem i'd like to do something like: <dtml-let checkbox="list(checkbox)"> ... ... </dtml-let> That is, calling the list function of Python on checkbox. But that doesn't work, neither <dtml-let checkbox="_.list(checkbox)"> Beside of this, is there a way to test if foo is a string or a sequence or whatever ?? Thanks. -- ______________________________________________________ Felipe Alvarez Harnecker. QlSoftware. Tel. 09.874.60.17 e-mail: felipe.alvarez@qlsoft.cl Potenciado por Ql/Linux http://www.qlsoft.cl ______________________________________________________
Felipe Alvarez Harnecker wrote:
Hi Zopistas,
it's a pain looking to variables defined in a form such as checkboxes that can be a string if one is selected or a sequence if many are.
to solve this problem i'd like to do something like:
<dtml-let checkbox="list(checkbox)"> ... ... </dtml-let>
That is, calling the list function of Python on checkbox.
But that doesn't work, neither <dtml-let checkbox="_.list(checkbox)">
Beside of this, is there a way to test if foo is a string or a sequence or whatever ??
Sounds like you might want this http://www.zope.org/Members/Zen/howto/FormVariableTypes Coerce your form fields into the types you require by using magic incantations of the form variablename:type. -- Steve Alexander Software Engineer Cat-Box limited
Beside of this, is there a way to test if foo is a string or a sequence or whatever ?? apart from changing your form to force the list type, you could try (untested code):
<dtml-let checkbox="(checkbox==_.str(checkbox) and [checkbox] or checkbox"> ... </dtml-let> There is no easy way to check whether a value in Zope is a list, tuple, or integer, but there is an easy way to check whether it is a string since strings are the only type left unchanged by the str function. More advanced type recognition generally requires trying various things and catching the exceptions that are raised. I have put a PythonMethod that does general type recognition in a HowTo at http://www.zope.org/Members/Duncan/RecogniseTypes -- Duncan Booth duncan@dales.rmplc.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? http://dales.rmplc.co.uk/Duncan
participants (3)
-
Duncan Booth -
Felipe Alvarez Harnecker -
Steve Alexander