In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "how to use Python's debugging tool PySnooper". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
PySnooper is so easy to use that developers can use it in any large code base without any setup. All you have to do is add a decorator and specify a path for the log output address by specifying the path as * parameters.
Currently, PySnooper has obtained 7047 Star,371 Fork on GitHub.
A function is written below, by returning a binary list. All we need to do is add the @ pysnooper.snoop () decorator:
Import pysnooper @ pysnooper.snoop () def number_to_bits (number): if number: bits = [] while number: number, remainder = divmod (number, 2) bits.insert (0, remainder) return bits else: return [0] number_to_bits (6)
The output is as follows:
Starting var:.. Number = 6 15 number 29 def number_to_bits 11.327032 call 4 def number_to_bits (number): 15 number 29 number 11.327032 line 5 if number: 15 number 29 line 11.327032 line 6 bits = [] New var:. Bits = [] 15 while number 29 line 11.327032 line 7 while number: 15 line 11.327032 line 8 number, remainder = divmod (number, 2) New var:. Remainder = 0 Modified var:.. Number = 3 15 remainder 29 bits.insert 11.327032 line 9 bits.insert (0, remainder) Modified var:.. Bits = [0] 15 while number 29 line 11.327032 line 7 while number: 15 line 11.327032 8 number, remainder = divmod (number, 2) Modified var:.. Number = 1 Modified var:.. Remainder = 1 15 remainder 29 bits.insert 11.327032 line 9 bits.insert (0, remainder) Modified var:.. Bits = [1, 0] 15 while number 29 line 11.327032 line 7 while number: 15 line 11.327032 line 8 number, remainder = divmod (number, 2) Modified var:.. Number = 0 15 remainder 29 bits.insert 11.327032 line 9 bits.insert (0, remainder) Modified var:.. Bits = [1, 1, 0] 15 while number 29 line 11.327032 line 7 while number: 15 line 11.327032 line 10 return bits 15 line 11.327032 return 10 return bits Return value:.. [1, 1, 0]
Characteristics
Stderr, you can export the selection to the specified file:
@ pysnooper.snoop ('/ my/log/file.log')
Look at the values of some non-local variables:
@ pysnooper.snoop (variables= ('foo.bar',' self.whatever'))
Displays the snoop line of the function called by the function:
@ pysnooper.snoop (depth=2) "how to use Python's debugging tool PySnooper" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.