[Python-ideas] Should __builtins__ have some kind of pass-through print function, for debugging?

Pradyun Gedam pradyunsg at gmail.com
Tue May 1 15:13:01 EDT 2018


On Fri, Apr 27, 2018 at 6:24 PM Nick Coghlan <ncoghlan at gmail.com> wrote:

> On 27 April 2018 at 21:27, Steven D'Aprano <steve at pearwood.info> wrote:
>
>> Obviously dp() would have to be magic. There's no way that I know of for
>> a Python function to see the source code of its own arguments. I have no
>> idea what sort of deep voodoo would be required to make this work. But
>> if it could work, wow, that would really be useful. And not just for
>> beginners.
>>
>
> If you relax the enhancement to just noting the line where the debug print
> came from, it doesn't need to be deep compiler magic - the same kind of
> stack introspection that warnings and tracebacks use would suffice. (Stack
> introspection to find the caller's module, filename and line number,
> linecache to actually retrieve the line if we want to print that).
>

I​ spent a bit of time and now there's a dprint <https://pypi.org/p/dprint>
project on PyPI. It uses stack introspection to print out some details. If
someone wants to take it for a spin and provide feedback on how it feels,
this thread is as good a place as any, I suppose. :)

Cheers,
Pradyun


> Cheers,
> Nick.
>
> P.S. While super() is a *little* magic, it isn't *that* magic - it gets
> converted from "super()" to "super(name_of_first_param, __class__)". And
> even that limited bit of magic has proven quirky enough to be a recurring
> source of irritation when it comes to interpreter maintenance.
>
> --
> Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
--

Pradyun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180501/ccef7227/attachment.html>


More information about the Python-ideas mailing list