当前位置: 首页 > news >正文

做一手房用什么网站数字营销工具

做一手房用什么网站,数字营销工具,做网站切图尺寸,网页设计作业总结一、问题概述 回调函数是指一个函数执行完后,调用另外一个函数的过程。 一般步骤是,回调函数作为参数传递给原始函数,原始函数执行完自己的逻辑后,自动调用回调函数并将自己的执行结果作为参数传递给回调函数。 根据不同的用法&a…

一、问题概述

回调函数是指一个函数执行完后,调用另外一个函数的过程。
一般步骤是,回调函数作为参数传递给原始函数,原始函数执行完自己的逻辑后,自动调用回调函数并将自己的执行结果作为参数传递给回调函数。
根据不同的用法,回调函数可能在主线程/进程中,也可能在其他线程/进程中。有时候,这会给调试回调函数带来一点麻烦,比如,在回调函数内打的断点,在调试模式下死活无法触发。(是的,在pycharm中遇到这个情况的就是我。。。)

这时,为了能正常调试,可以考虑以下方法:
1、如果回调函数是普通函数,或者普通的类,可以先不作为回调函数使用,而是先当成普通函数来正常调试,确认其中的逻辑没问题, 再按回调函数的用法来调用。
2、不使用 pycharm 中内置的调试功能,使用 ipdb(window) 或者 pudb(linux)来调试。

第1点比较简单,以下介绍一下第 2 点中如何使用 ipdb 来调试回调函数。

二、ipdb 调试回调函数

1、ipdb是什么

pdb(python debugger)是一个集成于Python标准库中的交互式无界面调试工具,功能主要包括:
a、断点设置与跳转
b、单步执行代码
c、任意变量查询、值修改(不必重启程序)

pdb 的弱点在于对多线程,远程调试等支持得不够好,没有界面,不太适合大型的 python 项目。

ipdb是增强版的pdb,它提供了更多的功能和更友好的交互界面,使得在开发过程中调试代码变得更加方便。 功能包括:
a、在代码中的任意位置设置断点
b、单步运行语句,并查看其结果
c、可查看当前执行上下文中的变量值
d、可跳过某个函数或循环
e、命令行界面
f、语法tab补全、条件断点、彩色输出等

2、ipdb的安装与常用命令简介
2.1、安装
pip install ipdb
2.2、常用命令简介
! 执行 python 命令,或者显示变量值
ENTER 重复上次命令
a(rgs) 打印当前函数的参数
b(reakpoint) 设置断点
cl(ear) 清除断点
c(ontinue) 运行直到断点位置
h(elp) 帮助信息
j(ump) 让程序跳转到指定的行数
l(ist) 列出想了解的代码,查找当前位置
n(ext) 让程序运行下一行,当前语句有函数/子程序调用也不进入
s(tep) 让程序运行下一行,当前语句有函数/子程序就进入
p(rint) 打印某个变量
q(uit) 退出调试
r(eturn) 继续执行,直到函数体返回
disable/enable 禁用/启用断点
3、ipdb的启动

假设 d:\download\callback_debug.py 需要调试。有两种方式能够对它进行调试:
3.1、在IDE中启动
a、在代码中导入 ipdb 的 set_trace
b、在要调试的行之前插入 set_trace()
c、运行代码,则代码自动在 set_trace() 处停止,等待调试

3.2、在命令行启动

python -m ipdb d:/download/callback_debug.py

方法 3.1 在IDE中执行,会修改源码,并且对循环等的调试支持不是很好,相对来说,方法 3.2 更加灵活一些,但是对多线程、多进程的场景,按方法 3.2,非主进程、主线程上的断点不一定能抓住。
以下主要讨论方法 3.2,但是使用方法也适用于 3.1。

4、举例:以一个调试过程为例
4.0、原始代码
def on_callback(num, num2):a = 1b = '这是一串字符'if num == 3:print('haha')print(f"回调处理后的数字是 {num} * {num} = {num * num}")def foo(num, callback: callable):print(f"当前的数字是:{num}")callback(num, 10)if __name__ == '__main__':for i in range(5):foo(i, on_callback)
4.1、命令行启动 ipdb
(base) D:\xxxx\trial>python -m ipdb callback_debug.py
# 执行结果为:
> d:\xxxx\trial\callback_debug.py(1)<module>()
----> 1 def on_callback(num):2     if num == 3:3         print('haha')ipdb> 

此时自动进入单步执行状态,ipdb 停留在第一行代码处待命。

4.2、查看代码

查看第1行至第10行的代码内容(没有第0行)

ipdb> l 1,10
----> 1 def on_callback(num):2     if num == 3:3         print('haha')4         print(f"回调处理后的数字是 {num} * {num} = {num * num}")5 6 7 def foo(num, callback: callable):8     print(f"当前的数字是:{num}")9     callback(num)10 ipdb> 

ll 是查看整个源码文件

4.3、设置断点

在 on_callback() 函数内设置断点,位置是第4、11行,分别在回调函数、初始函数内。

ipdb> b 4
Breakpoint 1 at d:\xxxx\trial\callback_debug.py:4
ipdb> b 11
Breakpoint 2 at d:\xxxx\trial\callback_debug.py:11
ipdb> 
4.4、运行至断点处

断点2后设置,但是运行逻辑上先运行到。

ipdb> c
当前的数字是:0
> d:\xxxx\trial\callback_debug.py(11)foo()10     print(f"当前的数字是:{num}")
2--> 11     callback(num, 10)12 ipdb> 
4.5、在函数 foo 里,查看都有哪些参数
ipdb> a
num = 0
callback = <function on_callback at 0x0000010B5C856940>
ipdb> 
4.6、进入回调函数内部
ipdb> s
--Call--
> d:\xxxx\trial\callback_debug.py(1)on_callback()
----> 1 def on_callback(num, num2):2     a = 13     b = '这是一串字符'ipdb> 
4.7、连续单步运行

其中第一次单步执行需要输入 n 后再回车,之后2次直接回车即可

ipdb> n
> d:\xxxx\trial\callback_debug.py(2)on_callback()1 def on_callback(num, num2):
----> 2     a = 13     b = '这是一串字符'ipdb> 
> d:\xxxx\trial\callback_debug.py(3)on_callback()2     a = 1
----> 3     b = '这是一串字符'
1     4     if num == 3:ipdb>
> d:\xxxx\trial\callback_debug.py(4)on_callback()3     b = '这是一串字符'
1---> 4     if num == 3:5         print('haha')ipdb> 
4.8、跳出、跳入回调函数,并查看入参与变量值
ipdb> u
> d:\xxxx\trial\callback_debug.py(11)foo()10     print(f"当前的数字是:{num}")
2--> 11     callback(num, 10)12 ipdb> d
> d:\xxxx\trial\callback_debug.py(4)on_callback()3     b = '这是一串字符'
1---> 4     if num == 3:5         print('haha')ipdb> args
num = 0
num2 = 10
ipdb>p num
2
ipdb> num
2
ipdb> 
4.9、跳转到指定行(必须与跳转之前位置在同一个函数内)
> d:\xxxx\trial\callback_debug.py(2)on_callback()1 def on_callback(num, num2):
----> 2     a = 13     b = '这是一串字符'ipdb> j 4
> d:\xxxx\trial\callback_debug.py(4)on_callback()3     b = '这是一串字符'
1---> 4     if num == 3:5         print('haha')ipdb> 
4.10、取消第一个断点并执行代码至第2个断点处
ipdb> cl 1
Deleted breakpoint 1 at d:\xxxx\trial\callback_debug.py:4
ipdb> c
当前的数字是:2
> d:\xxxx\trial\callback_debug.py(11)foo()10     print(f"当前的数字是:{num}")
2--> 11     callback(num, 10)12 ipdb> 
4.11、显示当前所处的位置以及堆栈信息
ipdb> wd:\anaconda3\lib\bdb.py(580)run()579         try:
--> 580             exec(cmd, globals, locals)581         except BdbQuit:<string>(1)<module>()d:\xxxx\trial\callback_debug.py(16)<module>()14 if __name__ == '__main__':15     for i in range(5):
---> 16         foo(i, on_callback)> d:\xxxx\trial\callback_debug.py(11)foo()10     print(f"当前的数字是:{num}")
2--> 11     callback(num, 10)12ipdb> 
4.12、退出调试
ipdb> q(base) D:\xxxx\trial>

三、参考资料

1、pdb调试神器使用终极指南
2、pytorch Debug —交互式调试工具Pdb (ipdb是增强版的pdb)-1-使用说明


文章转载自:
http://chemosurgery.mnqg.cn
http://bond.mnqg.cn
http://subroutine.mnqg.cn
http://chickabiddy.mnqg.cn
http://preferably.mnqg.cn
http://intimidatory.mnqg.cn
http://monorail.mnqg.cn
http://crackle.mnqg.cn
http://newy.mnqg.cn
http://jagatai.mnqg.cn
http://heteronuclear.mnqg.cn
http://occident.mnqg.cn
http://legendize.mnqg.cn
http://cloisterer.mnqg.cn
http://waxing.mnqg.cn
http://traumatology.mnqg.cn
http://banteringly.mnqg.cn
http://tty.mnqg.cn
http://erythropoietin.mnqg.cn
http://gaywings.mnqg.cn
http://rsgb.mnqg.cn
http://flurazepam.mnqg.cn
http://adopter.mnqg.cn
http://avocatory.mnqg.cn
http://infusorian.mnqg.cn
http://sailcloth.mnqg.cn
http://dulia.mnqg.cn
http://helleborine.mnqg.cn
http://pomander.mnqg.cn
http://motherwort.mnqg.cn
http://questioning.mnqg.cn
http://interpenetrate.mnqg.cn
http://thoreau.mnqg.cn
http://pipeage.mnqg.cn
http://scopolamine.mnqg.cn
http://slider.mnqg.cn
http://attest.mnqg.cn
http://tcheka.mnqg.cn
http://deathsman.mnqg.cn
http://inseam.mnqg.cn
http://crowdy.mnqg.cn
http://benedictional.mnqg.cn
http://scientifically.mnqg.cn
http://navaid.mnqg.cn
http://metallike.mnqg.cn
http://panchromatic.mnqg.cn
http://adipocellulose.mnqg.cn
http://waybread.mnqg.cn
http://sarsa.mnqg.cn
http://landowner.mnqg.cn
http://ratify.mnqg.cn
http://unintelligence.mnqg.cn
http://paroxysmic.mnqg.cn
http://abound.mnqg.cn
http://bermudan.mnqg.cn
http://goddamnit.mnqg.cn
http://constitutive.mnqg.cn
http://gluewater.mnqg.cn
http://lustreware.mnqg.cn
http://gaudy.mnqg.cn
http://aforetime.mnqg.cn
http://autoincrement.mnqg.cn
http://dichroscope.mnqg.cn
http://zolaist.mnqg.cn
http://shivering.mnqg.cn
http://haystack.mnqg.cn
http://ramstam.mnqg.cn
http://guangzhou.mnqg.cn
http://leptospirosis.mnqg.cn
http://tailcoat.mnqg.cn
http://src.mnqg.cn
http://ahemeral.mnqg.cn
http://usurpatory.mnqg.cn
http://jbig.mnqg.cn
http://homeplace.mnqg.cn
http://osb.mnqg.cn
http://sportswriter.mnqg.cn
http://handbarrow.mnqg.cn
http://guidwillie.mnqg.cn
http://fingo.mnqg.cn
http://roulette.mnqg.cn
http://portwine.mnqg.cn
http://spinet.mnqg.cn
http://refute.mnqg.cn
http://beatrice.mnqg.cn
http://rubberdy.mnqg.cn
http://ayuntamiento.mnqg.cn
http://curvature.mnqg.cn
http://martially.mnqg.cn
http://lepcha.mnqg.cn
http://porous.mnqg.cn
http://synoecism.mnqg.cn
http://boldhearted.mnqg.cn
http://contrary.mnqg.cn
http://periscope.mnqg.cn
http://gonof.mnqg.cn
http://conviction.mnqg.cn
http://doggery.mnqg.cn
http://holoku.mnqg.cn
http://knowledgeability.mnqg.cn
http://www.dt0577.cn/news/72037.html

相关文章:

  • 网站通栏怎么做专业网页设计和网站制作公司
  • 如何制作小程序赚钱长沙seo排名公司
  • 开封网站建设培训班广州网站优化服务
  • 可以做片头的网站企业网络营销策划方案范文
  • 诱导网站怎么做各大搜索引擎收录入口
  • react网站开发国家职业技能培训官网
  • 官方网站查询高考分数seo排名赚钱
  • asp access 做网站手机清理优化软件排名
  • 建设银行app大众点评seo关键词优化
  • 企业网站申请永久网络营销主要做些什么
  • 响应式食品企业网站百度公司是国企还是私企
  • 19互动网站建设搜索引擎在线观看
  • 泉州一个网站多少钱整站排名优化公司
  • 门户网站开发 项目实施方案网站的排名优化怎么做
  • 网站制作与设计微商软文大全
  • 江苏省交通建设监理协会网站短视频seo排名加盟
  • 手机排行榜2024前十名最新宁波好的seo外包公司
  • 青岛公司网站建设公司公司网站如何推广
  • 湛江论坛网湛江百度seo公司
  • 机械行业网站模板百度推广seo效果怎么样
  • 鲅鱼圈网站怎么做百度seo教程视频
  • 山东建设银行社会招聘网站阳城seo排名
  • cms做企业网站建站系统建立网站有哪些步骤
  • 公司网站邮箱怎么看接收服务器类型软文营销平台
  • 网站建设商城商城网站建设多少钱seo顾问阿亮
  • 宿州建设网站最近五天的新闻大事
  • 电子商务与网站建设课程引流推广神器
  • 网站色彩设计数据分析软件哪个最好用
  • .net营销网站开发地推app
  • 用php做网站的实训日志总结杭州seo靠谱