[Zope] brain hurts regarding dynamic fcn args in Python

Chris McDonough chrism@digicool.com
19 Jun 2000 22:50:47 +0200


> Is there a (straightforward?) way to dynamically compose function
> argument lists?  For example, in C, you can write"
> 
> f(arg1, arg2, (conditional expression)?(val for TRUE 
> state):(val for FALSE state)).

This can be emulated in Python by the boolean logic:

( ({conditional expression}) and {TRUE val} ) or {FALSE val}

e.g.

a = ( ( (x > 1) and "biggerthanone" ) or "smallerthanone" )

>>> x = 0
>>> a = ( (x > 1) and "biggerthanone" ) or "smallerthanone"
>>> a
'smallerthanone'

> 
> Or  one can embed a fcn call within an argument list in order 
> to supply a
> needed function parameter.


Hrm.. I *think* this will work as a function argment.  Sure.. why not?


_______________________________________________
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 )


---