
Had an idea on another thread (doctest) about a special exception called "Debug" that could could be raised to generate arbitrary output to stderr. This would be used instead of spurious print statements in code to inform developers during debugging (which might throw off doctest, for example). It could also replace "assert" (and improve upon it) which seems to be deprecated. Also, the __debug__ global could actually gain some functionality... Its "argument" could be an `eval`uatable string (checked at compile time) and it's output, this very string *plus* the output of it (if it evaluates to something different than itself). Just an idea.... mark santa fe

On Mon, Feb 27, 2012 at 09:34:02PM -0700, Mark Janssen wrote:
Printing to sys.stderr does not throw off doctest. If you use print(something, file=sys.stderr) # Python 3 print >>sys.stderr, something # Python 2 the output is invisible to doctest.
It could also replace "assert" (and improve upon it) which seems to be deprecated.
What makes you think assert is deprecated? Informational messages printed to stderr and assertions are completely different functions. You can't replace one with the other.
Also, the __debug__ global could actually gain some functionality...
What makes you think it doesn't? __debug__ is very useful for conditional compilation of debugging code that is safe to optimise away when running under -O. I use it in most of my projects.
So you mean, anything except a quine would be printed? I don't get what you mean, or how you intend for this to be used. -- Steven

On 2/27/2012 11:34 PM, Mark Janssen wrote:
Raising an exception to generate a log message? You'd never execute the statement after the raise, completely destroying the flow of the code. Perhaps this idea needs a little more thought... Have you looked into the logging module? --Ned.

On Mon, Feb 27, 2012 at 09:34:02PM -0700, Mark Janssen wrote:
Printing to sys.stderr does not throw off doctest. If you use print(something, file=sys.stderr) # Python 3 print >>sys.stderr, something # Python 2 the output is invisible to doctest.
It could also replace "assert" (and improve upon it) which seems to be deprecated.
What makes you think assert is deprecated? Informational messages printed to stderr and assertions are completely different functions. You can't replace one with the other.
Also, the __debug__ global could actually gain some functionality...
What makes you think it doesn't? __debug__ is very useful for conditional compilation of debugging code that is safe to optimise away when running under -O. I use it in most of my projects.
So you mean, anything except a quine would be printed? I don't get what you mean, or how you intend for this to be used. -- Steven

On 2/27/2012 11:34 PM, Mark Janssen wrote:
Raising an exception to generate a log message? You'd never execute the statement after the raise, completely destroying the flow of the code. Perhaps this idea needs a little more thought... Have you looked into the logging module? --Ned.
participants (3)
-
Mark Janssen
-
Ned Batchelder
-
Steven D'Aprano