if not DEBUG: log = null_log

Simon Burton simon at arrowtheory.com
Tue Jul 12 21:00:14 EDT 2005


Hi,

I'm after a no-op command, so that i can redirect
logging commands in performance critical code.

Something like this:

def log(*args): print args
def null_log(*args): pass
if not DEBUG: log = null_log

is unacceptable because of the overhead of calling
functions in python.

log ("about to slip into python feature request mode.")

Maybe this is what the PEP 336 guy was thinking of (Make None Callable).
Obviously we don't want None to be callable, but
what about a "Null" [1] that's callable, with any args ?

But I guess what I am really asking for is something on the bytecode
level that tells the VM to "do nothing". 

Here's an idea: make "pass" into an expression (a value) that is callable, 
with any args, and returns None.

log ("finished with python feature request mode.")

I recently discovered "pyc" [2], but i don't quite see how i can
use it while maintaining python source compatability.

bye!

Simon.

[1]: http://occs.cs.oberlin.edu/~jwalker/nullObjPattern/
[2]: http://students.ceid.upatras.gr/~sxanth/pyc/

-- 
Simon Burton, B.Sc.
Licensed PO Box 8066
ANU Canberra 2601
Australia
Ph. 61 02 6249 6940
http://arrowtheory.com 



More information about the Python-list mailing list