文章目录
前言
前两天在调试一个巨大的程序,跑起来都要几个小时,经过把训练集替换成测试集之后才快了一些,但是仍然有中途崩溃的问题。期间想了各种办法,并总结了这篇文章。
Debug是一门非常使用的技巧,一旦学会终身受益,而且这方面也很少有人去教我们。本文主要记录一些调试技巧
Pycharm Debug
hook 函数
my_hook_target_function_name = 'fun_to_hook' hook_function_tmp_storage = eval(my_hook_target_function_name) def _hook_target_function_replacement(*args): hook_function_tmp_storage(*args) # do your things print('hook method [' + my_hook_target_function_name + ']...') exec(my_hook_target_function_name + '=_hook_target_function_replacement')
修改fun_to_hook并在_hook_target_function_replacement函数体内写hook之前或者之后的代码即可。在某些监视函数执行前的时机,例如查看当时的变量环境等可能会用到。
debug console
基于支持正则的文本编辑器批量修改
写代码的过程中我们常常需要把一部分代码迁移或者批量替换,虽然只是些文本,但是为了这个重新写一个py文件with open('file') as f、 re.findall、 re.sub、 replace实在太过冗余。其实直接在编辑器上修改就行了
在正则支持这一点和sublime、vscode是一样的
比如以下几个案例
把文本中的偶数和奇数分离
例如有以下文本 匹配[02468]
0
0 31
进阶,把奇数偶数交换

首先将偶数选中,拷贝保存到文件t_file里,并替换成t
ttttttttttttttttttttttttttttttt
然后正则选中想要替换的奇数,拷贝并替换成x
// Navigator.pushNamed(context, "/image_preview", arguments: message); // Navigator.pushNamed(context, "/video_play", arguments: message); // Navigator.pushNamed(context, "/file_preview", arguments: message); // Navigator.pushNamed(context, "/webview", arguments: param); // Navigator.pushNamed(context, "/webview", arguments: param); // Navigator.pushNamed(context, "/image_preview", arguments: tempMsg); // Navigator.pushNamed(context, "/file_preview", arguments: tempMsg); // Navigator.pushNamed(context, "/webview", arguments: param);
Get.toNamed("/image_preview", arguments: message); Get.toNamed("/video_play", arguments: message); Get.toNamed("/file_preview", arguments: message); Get.toNamed("/webview", arguments: param); Get.toNamed("/webview", arguments: param); Get.toNamed("/image_preview", arguments: tempMsg); Get.toNamed("/file_preview", arguments: tempMsg); Get.toNamed("/webview", arguments: param);
或者用于把散落在每一行得模式1代码和模式2代码交换
后续探索
code-server 远程调试
第二天早上检验。Word天!变量依然是保存的。
至于对特大程序vscode是否会采用另外一种策略还不得而知。
参考资料
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/220286.html原文链接:https://javaforall.net
