cool-RR / PySnooper

Never use print for debugging again
MIT License
16.34k stars 951 forks source link

Add Memory address information to debug print #179

Closed iory closed 4 years ago

iory commented 4 years ago

This PR adds debug prints of variables' memory addresses. The following is sample code and output.

In [1]: import pysnooper
   ...:
   ...:
   ...: def sample_a():
   ...:     with pysnooper.snoop():
   ...:         a = 5
   ...:         print(hex(id(a)))
   ...:         b = 7
   ...:         print(hex(id(b)))
   ...:         c = a * b
   ...:         print(hex(id(c)))
   ...:
   ...:
   ...: sample_a()
   ...:
Source path:... <ipython-input-1-aa3d4b446d39>
21:09:17.797662 line         6         a = 5
New var:....... a = 5 @ 0x107306500
21:09:17.797763 line         7         print(hex(id(a)))
0x107306500
21:09:17.797810 line         8         b = 7
New var:....... b = 7 @ 0x107306540
21:09:17.797839 line         9         print(hex(id(b)))
0x107306540
21:09:17.797878 line        10         c = a * b
New var:....... c = 35 @ 0x1073068c0
21:09:17.797906 line        11         print(hex(id(c)))
0x1073068c0
cool-RR commented 4 years ago

Got an example use case? This sounds a bit esoteric to me.

iory commented 4 years ago

Certainly, it may be difficult. I close this PR.