MrCreditRepair.biz will fix your credit rating!

just had an epiphany. sometimes I need really verbose debugging messages when testing, but don't want to see all that crap when running the program with full data. so I took an idea I had years ago for JavaScript and adapted it for Python:

COMMAND = os.path.splitext(os.path.basename(sys.argv[0]))[0]
logging.debug('COMMAND: %s', COMMAND)
DOCTESTDEBUG = logging.debug if COMMAND == 'doctest' else lambda *x: None

that lambda x: None construct simply creates a no-op that accepts any number of args. now I can sprinkle DOCTESTDEBUG('array is: %s', listing) statements in my routines and know they'll only be executed during doctests. neat, huh?

what I used to use for JavaScript stopped working a few years back. it switched between alert(something) and console.log(something). but now if console.log isn't working I just put in alerts until I find the broken statement. rarely necessary any more, which is good, because I've forgotten the exact syntax I used and don't know if I ever figured out what in the ECMAScript changes broke it.

Back to blog or home page

last updated 2017-01-23 14:28:22. served from tektonic