How do you use `help` when write your code

Cameron Simpson cs at
Mon Jul 7 03:51:45 CEST 2014

On 06Jul2014 15:15, Roy Smith <roy at> wrote:
>In article <mailman.11552.1404673207.18130.python-list at>,
> Mark Lawrence <breamoreboy at> wrote:
>> In the 21st century real programmers are using the logging module so
>> they don't have to mess around.
>The problem with the logging module is you can configure it to do pretty
>much anything, which is another way of saying if it's not configured
>right (perhaps because you're running your application in an environment
>it wasn't designed for), your output disappears into the ether.
>I can't tell you how many times I've given up fighting with logging and
>just done "open("/tmp/x").write("my debugging message\n") when all else

Indeed. I have a cs.logutils module, which is almost entirely support for the 
logging module (standard setups, funky use cases), but it also defines two 
functions, X and D, thus:

     def X(fmt, *args):
       msg = str(fmt)
       if args:
         msg = msg % args

     def D(fmt, *args):
       ''' Print formatted debug string straight to sys.stderr if D_mode is true,
           bypassing the logging modules entirely.
           A quick'n'dirty debug tool.
       global D_mode
       if D_mode:
         X(fmt, *args)

I use X() for ad hoc right now debugging and D() for turn on at need debugging.

Surprisingly handy. Many many of my modules have "from cs.logutils import X, D" 
at the top.

Cameron Simpson <cs at>

"How do you know I'm Mad?" asked Alice.
"You must be," said the Cat, "or you wouldn't have come here."

More information about the Python-list mailing list