In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the ways to debug Python". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "What are the ways of Python debugging"!
For scripting languages, the easiest way to debug is to print output, and the print function can output various types of variables, with formatted output, we can print out the state values of various variables during the program operation.
The advantage of using this approach is that we don't need to introduce other packages, we can debug our program using simple print, of course, its disadvantages are obvious, sometimes we have to write a lot of print statements to debug some variables, and sometimes we have to write a lot of code to display data more elegantly.
Icecream
This is a debug output plug-in, compared to the print function, it can automatically output various variable types gracefully, it will output the location of the variable, it can output the value of the function, it can also output the value to the log.
By introducing the icecream package, we can more easily and elegantly output debug variables and function values in our programs, but it, like the print function, does not solve the intrusive problem of debugging and generates debug code.
PySnooper
We mentioned earlier that print and icecream both generate debugging code, and we still need to delete them after debugging. Is there a non-intrusive way to debug? The answer is yes, that is, pysnooper.
Pysnooper uses decorators to debug code non-invasively, and the information it outputs is very detailed. We can clearly see the invocation hierarchy of functions and clearly see the change process of variable values. And it is the output location configuration that supports debugging information. By default, it is output in the console. Of course, we can also output debugging in the log.
pdb
We know that debugging c language when there is gdb, and debugging python, we have pdb, it is very similar to gdb, we can set breakpoints, you can debug line by line, you can enter breakpoints, you can set to modify variable values, with the IDE, you can say that pdb is our most commonly used, but also the most convenient debugging method.
By setting breakpoints, we can see the values of running variables without writing any code at all, and by debugging line by line, it also helps us analyze the code.
At this point, I believe that everyone has a deeper understanding of "what are the ways of Python debugging", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.