Home  >  Article  >  Backend Development  >  How to debug python code

How to debug python code

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-18 13:08:036334browse

python调试代码的方式有很多种,比如pdb 模块、利用 PyDev 和 Eclipse 集成进行调试、PyCharm 以及 Debug 日志进行调试等等。下面以pycharm调试来为大家介绍一下如何调试代码。

How to debug python code

PyCharm 是由 JetBrains 打造的一款 Python IDE,具有语法高亮、Project 管理、代码跳转、智能提示、自动完成、单元测试、版本控制等功能,同时提供了对 Django 开发以及 Google App Engine 的支持。PyCharm 同时提供了较为完善的调试功能,支持多线程,远程调试等,可以支持断点设置,单步模式,表达式求值,变量查看等一系列功能。

打开pycharm,新建一个python程序,命名为excel.py,是用python操作excel的。

相关推荐:《python视频教程

How to debug python code

2.直接贴出代码,如果是hello world就不存调试的问题了!

import xlrd
import xlwt
def readexcel():    #这个部分是读取内容    
workbook=xlrd.open_workbook(r'E:\百度经验\11.xlsx')    
print (workbook.sheet_names())  #输出页签名    
sheet2=workbook.sheet_by_name('A')  #打开页签    
nrows=sheet2.nrows  #获取行数    
ncols=sheet2.ncols  #获取列数    
print(nrows,ncols) #输出结果    
cell_A=sheet2.cell(1,1).value #取出第二行第二列的值    
print(cell_A)  #输出结果
if __name__ == '__main__':    
readexcel()

How to debug python code

3.介绍调试的菜单操作,在【菜单栏】选择【RUN】,下拉菜单里选择【debug excel.py】或者【Debug...】,这两个功能是一样的,都是调试功能

How to debug python code

4.介绍快捷键调式,调试:CTRL+SHLFT+F9,执行是CTRL+SHLFT+F10,当前调试SHLFT+F9,当前执行SHLFT+F10,还有很多,如下图所示:

How to debug python code

5.贴出调试的结果,会具体提示一些警告或者异常,因为本例已经调试过,所以没有异常

How to debug python code

The above is the detailed content of How to debug python code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn