[Tutor] Is defining functions as dummies pythonic?

Karl Pflästerer sigurd at 12move.de
Thu Apr 15 16:41:12 EDT 2004

On 15 Apr 2004, Scot W. Stevenson <- scot at possum.in-berlin.de wrote:

> where "isverbose" is a bool. After a while, this got to be a bore, and I 
> rewrote the whole thing by starting with:

> if isverbose:
>     def verbosize(text=""):
>         print text
> else:
>     def verbosize(text=""):
>         pass

> and then plastered the whole program with 

> verbosize("(Somewhat informative text)")

> This works fine, and if I understand the way the lower reaches of Python 
> work, it should be faster, since I got rid of a bunch of "if"s and turned 
> them into "passes" (which I hope the compiler completely gets rid of.

> However, defining functions based on parameters seems to be, well, strange, 
> if not downright C-preprocessoresque. Is there any reason _not_ to do things 
> this way, or, even better, is there a standard way to handle verbose program 
> output I'm just not aware of?

I would simply write:

def verbosize (string):
    if isverbose:
        print string

I don't know if there is a standard way (I don't believe it).  I also
don't see a reason to do it your way if *you* feel fine with it.  At
least you have to read and write your code.  And that makes only fun if
the code is written in a way that you have a cozy feeling about it (I
don't know how to describe it better; you must feel at home when you
look at the code in your editor).

Please do *not* send copies of replies to me.
I read the list

More information about the Tutor mailing list