[Tutor] Is defining functions as dummies pythonic?
Scot W. Stevenson
scot at possum.in-berlin.de
Thu Apr 15 14:15:18 EDT 2004
Hello there,
I'm writing a program where I let the user use a "-v" option to decide if he
wants the output to be verbose. At the beginning, I was putting lots of
lines such as:
if isverbose:
print "(Somewhat informative text)"
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?
As always, thank you again for the help!
Y, Scot
--
Scot W. Stevenson - Panketal, Germany
More information about the Tutor
mailing list