How do you avoid leaving print / pdb debugging commands in python-based open source applications when you debug and finish them?

Sometimes when developing using open source software, you need to read its source code (especially zope / plone). Many times I need to write print instructions, or debug calls (import pdb), or comment on try / except, you name it.

Sometimes I have many files open when trying to find a problem, and sometimes I forget to delete these print / debug changes.

So my question is: how do you keep yourself organized when you do this? You write "TODO" along with the changes and look for them later, you keep everything in your editor, and when you find what you are looking for, you simply return the files (this approach will not come in handy when you are looking for a really big problem that takes days, Do you need to turn off the computer and return the next day)? Or are you just doing nothing, because print statements in the development environment have nothing to worry about?

I am using Vim. I'm just curious to know how other programmers view this problem.

+3
source share
5 answers

. , , find/grep script, . , , grep .

- :

## pre-checkin_scan.bin
find . -name "*.py" -exec grep -H --file=/homes/js/bin/pre-checkin_scan_regexp_list.grep {} \;



## pre-checkin_scan_regexp_list.grep
## (The first pattern is to ignore Doxygen comments)

^##[^@]
pdb
^ *print *( *" *Dbg
^ *print *( *" *Debug
^ *debug
+2

. , diff, , , , . , , . , uncommit, ( DVCS git bzr, subversion).

, , . , , diff.

, diff, , Eclipse, .

+3

+1 . , - . pdb , git. emacs. , pdb . . , , diff. .

+2

Python Vim. . , "# XXX" . , ( ) XXX .

Vim , . , . , Vim ( GTK Gvim), .

. , :

:  ... :

, , . , .

+1

:

  • . , , :
# Set this to True to enable Debug code
XYZ_Debug = False

if XYZ_Debug:
    do_debugging()

, , logging (PyMOTW). , :

import logging

# Set this to True to enable debug
XYZ_Debug = False

log = logging.getLogger("XYZ")
log.setLevel(logging.DEBUG if XYZ_Debug else logging.INFO)


log.debug("debug output")
  1. ( ) :
do_debug_code() # XYZZY

Ibuffer Emacs, Python, . find/grep/sed, , .

  1. If you use Mercurial and know the Mercurial Queues (or you might want to examine them), save the debugging code as a patch in your queue. When you are ready for "production"; or pressing current changes; put the patch containing the debug code and go. You can achieve something like this outside of version control with diff and patch.
+1
source

Source: https://habr.com/ru/post/1779468/


All Articles