Using debug print routine inside assert

Edvard Majakari edvard+news at majakari.net
Wed Nov 5 05:05:21 EST 2003


Alex Martelli <aleax at aleax.it> writes:

> def debug(msg, *args):
>     if not must_do_some_output: return
>
>     if args:
>         msg = msg % args[0](*args[1:])
>
>     # proceed to output msg
>
> and called as

Gee - I'm impressed to receive answer to my original problem from
Martellibot himself :)

This is an excellent solution. I just realised it is backwards compatible
with my current system - calling debug('foo bar baf %s' %method_call())
works just fine with Alex's version; it just works the same as before, and
doesn't get any advantage from deferred parameter list evaluation. 

Of course there's still minor overhead in calling the method instead of
completely skipping it like with assert(), but usually that doesn't matter
at all.

-- 
#!/usr/bin/perl -w
$h={23,69,28,'6e',2,64,3,76,7,20,13,61,8,'4d',24,73,10,'6a',12,'6b',21,68,14,
72,16,'2c',17,20,9,61,11,61,25,74,4,61,1,45,29,20,5,72,18,61,15,69,20,43,26,
69,19,20,6,64,27,61,22,72};$_=join'',map{chr hex $h->{$_}}sort{$a<=>$b}
keys%$h;m/(\w).*\s(\w+)/x;$_.=uc substr(crypt(join('',60,28,14,49),join'',
map{lc}($1,substr $2,4,1)),2,4)."\n"; print;




More information about the Python-list mailing list