home archives github knives links
tags python
categories
only title title and content
python笔记

调试

命令行

直接停留在第一行

python3 -m pdb test.py

断点设置

import pdb
pdb.set_trace()

调试命令

命令 解释
break,b 设置断点
continue,c 继续执行程序
list,l 查看当前行的代码段
step,s 进入函数
return,r 从当前函数返回
exit,q 退出
next,n 执行下一行

TODO

语法

同一行输出

print('\rfuck', end = '')

打印行号

参考: stackoverflow

import inspect

def PrintFrame():
callerframerecord = inspect.stack()[1] # 0 represents this line
# 1 represents line at caller
frame = callerframerecord[0]
info = inspect.getframeinfo(frame)
print(info.filename) # __FILE__ -> Test.py
print(info.function) # __FUNCTION__ -> Main
print(info.lineno) # __LINE__ -> 13

def Main():
PrintFrame() # for this line

Main()

时间time的使用

参考: cnblogs

有误

配置

环境变量

/usr/local/lib/python3.8/dist-packages下创建xxx.pth, 添加需要添加的module路径如/home/lynx/.local/lib/python3.8/site-packages