>I don't understand why you think print or log debugging is inherently bad.
I use it myself all the time, but it just shows the weakness of the tooling that people have to resort to such measures. Fortunately, some people are working on it [1].
>Also, it's part of the format string and not a special print function so that it can be used for logs and other output as well, not just the console.
Since print (and hypothetical debug_print) are no longer statements like in 2.x, there's nothing preventing them from returning the string that's supposed to be printed. For example print's keyword file is sys.stdout by default. Why not borrow from Common Lisp's format and make it return the string if file=None is passed? Then you could do logging.warning(debug_print('Unusual situation', foo, bar, file=None)) and it would print "WARNING: Unusual situation: foo=foo_value, bar=bar_value" to the logs. It's so much clearer.
> I use it myself all the time, but it just shows the weakness of the tooling that people have to resort to such measures.
It's not resorting to anything. It's a valid means of debugging. People use it even in languages like c and Java and in-browser JavaScript with very capable debuggers. It's quick, simple, and doesn't require intervention to record or examine anything.
> Why not borrow from Common Lisp's format and make it return the string if file=None is passed?
Because thatsa terrible idea because it's non-intuitive, verbose, and potentially confusing. Debug format strings are common in other languages, such as rust, so this isn't some half-thoughtout, python-only idea.
That's poor compared to just logging.warning('Unusual situation', foo, bar).
I.e. since print isn't a statement, you can give other functions the same argument conventions that it has, instead of making the programmer use a string-generating shim.
Speaking of Common Lisp, it has functions other than format which take format arguments.
$ clisp -q
[1]> (error "value of ~s should be less than ~s" 'bloop 42)
*** - value of BLOOP should be less than 42
The following restarts are available:
I don't expect logging.warning to change in future versions of Python (currently it substitutes extra args as % operator, so you'd have to write logging.warning('Unusual situation foo=%s, bar=%s', foo, bar)) since it would unnecessarily break too much code. But since print doesn't return any usable value, it can be easily updated to return a useful value.
Also, it's part of the format string and not a special print function so that it can be used for logs and other output as well, not just the console.