Re: [Zope] brain hurts regarding dynamic fcn args in Python

2000-06-20 Thread Dieter Maurer

Jeff Sasmor writes:
  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)).
Others have pointed out, that you can use
"and" and "or" to emulate "? ... : ...".
Be careful, there are dangers, because the emulation is not faithful.

  In my case here in Zope, sometimes I have to search a ZCatalog
  prior to displaying the results in a dtml-in looping construct.
  
  dtml-in
  
 "Catalog.searchResults(meta_type='EventDoc',event_date=[first,last],event_date_usage='range:min:max',sort_on='event_date
  ')"
  

  /dtml-in
  
  
  Now if the 'moderated' property is active I want to add the keyword arg
  
  reviewed='on'
  
  to the arg list at the time that the searchResults method is invoked.
In some cases, you could use:
   ...(..., reviewed= moderated and 'on', ...)
This will define "reviewed". It will have a Python "false" value
if moderated is "false", otherwise the value 'on'.

If your function uses code like:
"if kw.has_key('reviewed') and kw['reviewed': ..."
this will work. If the second and term is missing, if won't.


I do not know, what code ZCatalog uses. Try it out or
look into the source.


Dieter


___
Zope maillist  -  [EMAIL PROTECTED]
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 )




RE: [Zope] brain hurts regarding dynamic fcn args in Python

2000-06-19 Thread Chris McDonough

 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  -  [EMAIL PROTECTED]
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 )




RE: [Zope] brain hurts regarding dynamic fcn args in Python

2000-06-19 Thread Chris McDonough

Oops, I'm not quite right about this.  This FAQ explains it better...

http://www.python.org/doc/FAQ.html#4.16

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
 Sent: Monday, June 19, 2000 4:51 PM
 To: [EMAIL PROTECTED]
 Subject: RE: [Zope] brain hurts regarding dynamic fcn args in Python
 
 
  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  -  [EMAIL PROTECTED]
 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 )
 
 
 ---
 
 ___
 Zope maillist  -  [EMAIL PROTECTED]
 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 )
 

___
Zope maillist  -  [EMAIL PROTECTED]
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 )