Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74068

Re: How do you use `help` when write your code

Date 2014-07-07 11:51 +1000
From Cameron Simpson <cs@zip.com.au>
Subject Re: How do you use `help` when write your code
References <roy-CE5D08.15151006072014@news.panix.com>
Newsgroups comp.lang.python
Message-ID <mailman.11568.1404699666.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 06Jul2014 15:15, Roy Smith <roy@panix.com> wrote:
>In article <mailman.11552.1404673207.18130.python-list@python.org>,
> Mark Lawrence <breamoreboy@yahoo.co.uk> 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
>failed.

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
       sys.stderr.write(msg)
       sys.stderr.write("\n")
       sys.stderr.flush()

     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.

Cheers,
Cameron Simpson <cs@zip.com.au>

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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

How do you use `help` when write your code Shiyao Ma <i@introo.me> - 2014-07-07 00:36 +0800
  Re: How do you use `help` when write your code Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-06 17:52 +0000
    Re: How do you use `help` when write your code Tim Chase <python.list@tim.thechases.com> - 2014-07-06 13:22 -0500
    Re: How do you use `help` when write your code Roy Smith <roy@panix.com> - 2014-07-06 14:48 -0400
  Re: How do you use `help` when write your code Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 11:48 -0700
    Re: How do you use `help` when write your code Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-07-06 19:58 +0100
      Re: How do you use `help` when write your code Roy Smith <roy@panix.com> - 2014-07-06 15:15 -0400
        Re: How do you use `help` when write your code Chris Angelico <rosuav@gmail.com> - 2014-07-07 08:54 +1000
          Re: How do you use `help` when write your code Roy Smith <roy@panix.com> - 2014-07-06 20:52 -0400
            Re: How do you use `help` when write your code Chris Angelico <rosuav@gmail.com> - 2014-07-07 13:06 +1000
              Re: How do you use `help` when write your code Roy Smith <roy@panix.com> - 2014-07-07 07:22 -0400
                Re: How do you use `help` when write your code Chris Angelico <rosuav@gmail.com> - 2014-07-07 21:36 +1000
        Re: How do you use `help` when write your code Cameron Simpson <cs@zip.com.au> - 2014-07-07 11:51 +1000

csiph-web