boxx icon indicating copy to clipboard operation
boxx copied to clipboard

Extra magic for p, g, and gg using executing

Open alexmojaki opened this issue 5 years ago • 0 comments

With these changes, p will show the source code of expressions being printed and g can transport variables without specifying the name, e.g. g / y instead of g.y / y. Here's an example script:

from boxx import p, g, gg

x = [i * 2 for i in range(5)]
p / [p / x[0], p ** x[1], p - x[2], p << x[3], p >> x[4]]


def foo():
    y = 4
    z = 5
    gg / y
    g / z


foo()
print(y, z)

Output:

x[0] = 0
x[1] = 2
x[2] = 4
x[3] = 6
x[4] = 8
[p / x[0], p ** x[1], p - x[2], p << x[3], p >> x[4]] = [0, 2, 4, 6, 8]
gg.y:"4"
4 5

This is thanks to my library executing.

I would appreciate it if you could add some links to some of my other debugging libraries which I think your users would be interested in:

  • snoop: a better version of PySnooper. It includes a function pp.deep which is similar to logc but shows all sub-expressions, not just variables.
  • heartrate: a real time visualisation of a program similar to pyheat.

alexmojaki avatar Aug 11 '19 12:08 alexmojaki