This can be accomplished as a decorator. Jim Crist wrote a version of this using the codetransformer library. The usage is pretty simple:
@trace() def sum_word_lengths(words): total = 0 for w in words: word_length = len(w) total += word_length return total >>> sum_word_lengths(['apple', 'banana', 'pear', 'orange']) total = 0 w = 'apple' word_length = 5 total = 5 w = 'banana' word_length = 6 total = 11 w = 'pear' word_length = 4 total = 15 w = 'orange' word_length = 6 total = 21 21 The source for the trace decorator is in this available here: https://gist.github.com/jcrist/2b97c9bcc0b95caa73ce (I can't figure out how to link to a section, it is under "Tracing"). On Thu, Jan 25, 2018 at 4:03 PM, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote: > Steve Barnes wrote: >> >> I would suggest, however, that if this feature is introduced it be >> controlled via a run-time switch &/or environment variable which defaults to >> off. > > > I disagreew with defaulting it to off. That would encourage > lazy developers to distribute library code full of #l lines, > so that when you turn it on to debug something of your own, > you get swamped with someone else's debugging messages. > > -- > Greg > > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/