[Tutor] Is defining functions as dummies pythonic?
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Fri Apr 16 14:38:17 EDT 2004
> 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
[some text cut]
Hi Scot,
You might want to look at the 'logging' module:
http://www.python.org/doc/lib/module-logging.html
It's designed to handle several levels of verbosity, and is quite nice.
Good luck!
More information about the Tutor
mailing list