stylistic question -- optional return value

Sebastian Wangnick sebastian.wangnick at eurocontrol.int
Mon Sep 2 09:44:27 CEST 2002


> Andrew Koenig <ark at research.att.com> wrote:
> 
> > Hans> Still, I believe that rewriting the function (or splitting it up)
>  
> > Hans> might be a better idea. <0.3 wink>
> >
> > I've considered that, and I really don't think it works in this case.
> >
> > You might think of the optional result as being similar to debugging
> > information -- you really don't want to put the code that getnerates
> > debugging information into a separate function, because then it will
> > surely diverge from the code about which it is providing the informatio

If I understand you correctly then you'd like to be able to provide,
under circumstances determined by your function, additional
information back to your caller. Additionally, an "innocent" caller
should not be bothered with the additional information.

Why not create an additional optional *argument* (say a list, or a
function), to which you optionally provide your debug information?

def func(x,y,debug=None):
   if debug!=None: debug("func")
   return x+y

e = []
z = func(3,4,lambda info:e.append(info))
print z,e
 
Regards,
Sebastian

PS: I learned Python only last week, so take my posting with a grain
of salt.



More information about the Python-list mailing list