# with
import random
import pysnooper
def print_upper_mid_lower(): lst = [] for i in range(10): lst.append(random.randrange(1, 1000)) with pysnooper.snoop(): lower = min(lst) upper = max(lst) mid = (lower + upper) / 2 print(lower, mid, upper) if __name__ == '__main__': print_upper_mid_lower() # 结果 D:\miniconda3\python.exe D://调试库pysnooper.py 252 598.0 944 Source path:... D://pysnooper.py New var:....... lst = [295, 352, 493, 662, 887, 423, 385, 944, 252, 903] New var:....... i = 9 10:09:42.334110 line 24 lower = min(lst) New var:....... lower = 252 10:09:42.335114 line 25 upper = max(lst) New var:....... upper = 944 10:09:42.335114 line 26 mid = (lower + upper) / 2 New var:....... mid = 598.0 10:09:42.335114 line 27 print(lower, mid, upper) Elapsed time: 00:00:00.001004 Process finished with exit code 0
# 装饰器 import random import pysnooper @pysnooper.snoop() def print_upper_mid_lower(): lst = [] for i in range(10): lst.append(random.randrange(1, 1000)) lower = min(lst) upper = max(lst) mid = (lower + upper) / 2 print(lower, mid, upper) if __name__ == '__main__': print_upper_mid_lower() # 结果 D:\miniconda3\python.exe D://调试库pysnooper.py 81 484.5 888 Source path:... D://pysnooper.py 10:13:36.684644 call 7 def print_upper_mid_lower(): 10:13:36.685643 line 8 lst = [] New var:....... lst = [] 10:13:36.685643 line 9 for i in range(10): New var:....... i = 0 10:13:36.685643 line 10 lst.append(random.randrange(1, 1000)) Modified var:.. lst = [94] 10:13:36.685643 line 9 for i in range(10): Modified var:.. i = 1 10:13:36.685643 line 10 lst.append(random.randrange(1, 1000)) Modified var:.. lst = [94, 204] 10:13:36.685643 line 9 for i in range(10): Modified var:.. i = 2 10:13:36.685643 line 10 lst.append(random.randrange(1, 1000)) Modified var:.. lst = [94, 204, 81] 10:13:36.685643 line 9 for i in range(10): Modified var:.. i = 3 10:13:36.685643 line 10 lst.append(random.randrange(1, 1000)) Modified var:.. lst = [94, 204, 81, 512] 10:13:36.685643 line 9 for i in range(10): Modified var:.. i = 4 10:13:36.685643 line 10 lst.append(random.randrange(1, 1000)) Modified var:.. lst = [94, 204, 81, 512, 830] 10:13:36.685643 line 9 for i in range(10): Modified var:.. i = 5 10:13:36.685643 line 10 lst.append(random.randrange(1, 1000)) Modified var:.. lst = [94, 204, 81, 512, 830, 677] 10:13:36.685643 line 9 for i in range(10): Modified var:.. i = 6 10:13:36.685643 line 10 lst.append(random.randrange(1, 1000)) Modified var:.. lst = [94, 204, 81, 512, 830, 677, 888] 10:13:36.685643 line 9 for i in range(10): Modified var:.. i = 7 10:13:36.685643 line 10 lst.append(random.randrange(1, 1000)) Modified var:.. lst = [94, 204, 81, 512, 830, 677, 888, 737] 10:13:36.685643 line 9 for i in range(10): Modified var:.. i = 8 10:13:36.685643 line 10 lst.append(random.randrange(1, 1000)) Modified var:.. lst = [94, 204, 81, 512, 830, 677, 888, 737, 253] 10:13:36.685643 line 9 for i in range(10): Modified var:.. i = 9 10:13:36.685643 line 10 lst.append(random.randrange(1, 1000)) Modified var:.. lst = [94, 204, 81, 512, 830, 677, 888, 737, 253, 224] 10:13:36.685643 line 9 for i in range(10): 10:13:36.685643 line 12 lower = min(lst) New var:....... lower = 81 10:13:36.685643 line 13 upper = max(lst) New var:....... upper = 888 10:13:36.686644 line 14 mid = (lower + upper) / 2 New var:....... mid = 484.5 10:13:36.686644 line 15 print(lower, mid, upper) 10:13:36.686644 return 15 print(lower, mid, upper) Return value:.. None Elapsed time: 00:00:00.002000 Process finished with exit code 0
标签:10,13,打印,pysnooper,36.685643,lst,var,line,运行 From: https://www.cnblogs.com/daizichuan/p/17488773.html