[Tutor] Is defining functions as dummies pythonic?

Michael Janssen Janssen at rz.uni-frankfurt.de
Fri Apr 16 09:03:00 EDT 2004


On Fri, 16 Apr 2004, Scot W. Stevenson wrote:

> > I would simply write:
> >
> > def verbosize (string):
> >     if isverbose:
> >         print string
> >     else:
> >         pass
>
> But doesn't that mean that every time this function is called, the program
> has to do the test all over again, even though I already have the
> information from the start? This sound hideously inefficient...

the test itself should be very efficient especially compared against a
print operarion. Further you won't use such a function very often: it
prints text and the user has a limited capacity of reading text ;-)

Since it is a seldom used function you can put a lot of logic into it
without the user noting. I would bet a 100 if and elses aren't enough
to make a difference.

That's the good thing with all this efficiency issues: in most situations
it simply doesn't matter and you free to code the way it makes it best
readable/ understandable for you. Nevertheless, defining functions on
runtime is damned cool.


regards
Michael



More information about the Tutor mailing list