Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #88403
| References | <CAEMktPWzFDh7nQk9np_-SOHVOPo6R=9Vj0PjQCiumaYnnUNXAQ@mail.gmail.com> <mfe1kd$c80$1@ger.gmane.org> <CAEMktPXvknQE3-jNH6h-uxjE35t+pniXO_+9rX-pLEukRiAiaQ@mail.gmail.com> |
|---|---|
| From | Andrew Farrell <amfarrell@mit.edu> |
| Date | 2015-03-31 15:38 -0500 |
| Subject | Re: Project, how to debug |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.0.1427836034.12925.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
points of general advice: - As noted by Chris, you first need to figure out what the code is *supposed* to do. - Have a notebook and pencil next to you as you are working through this so that you can make notes and draw out the structure of things. - Write down the general structure of the code on your notebook so you always keep yourself oriented. If you find yourself lost, don't just keep reading code; stop and write out what you do understand and try to turn your sense of confusion into concrete questions. - Use The Silver Searcher <http://geoff.greer.fm/ag/>. If you find yourself thinking "I wish I could just see all the places where the variable 'herring' is used", then `ag -C 5 herring` is going to be your friend. - Use pdb <https://docs.python.org/2/library/pdb.html>, the python debugger that comes in the standard library. If you find yourself wanting to jump into a section of the code and print out variables and look at stack frames, sticking `import pdb;pdb.set_trace()` in there is going to be your friend. - Actually try using ipdb <https://docs.google.com/presentation/d/1c6BaV6T57z8UjkEd32xQErMtLT0fC-mZOCRaCcP7dcs/edit#slide=id.p>, which has a slightly better user interface than pdb. But don't worry if you can't install it. pdb is fine. - Much like you shouldn't just blindly read through code, don't just blindly step through code. If you lose sight of where you are, step back and re-orient yourself. - Find a colleague, friend, or rubber duck. Explain to them what you think the code is doing. This will force you to think about things more clearly. - Try writing unit tests for the code with with py.test <http://pytest.org/latest/>. It will help you verify "okay, this piece right here is working correctly" and thereby mean that you don't have to check that piece again. - Use assert statements to check that things are as they should be. - Try sticking `assert False` into the middle of a function. If the function raises an error other than AssertionError, then the problem is before the assert statement. - In your spare time, read 9 Indespensible Rules for Debugging Software and Hardware Problems <http://www.amazon.com/Debugging-Indispensable-Software-Hardware-Problems/dp/0814474578>. It is both useful and enjoyable. On Tue, Mar 31, 2015 at 7:05 AM, Robert Clove <cloverobert@gmail.com> wrote: > > > On Tue, Mar 31, 2015 at 5:19 PM, Peter Otten <__peter__@web.de> wrote: > >> Robert Clove wrote: >> >> > Hi All, >> > >> > I am facing a problem. >> > I have been given a project written in python and asked to debug it. >> > I have not been given the flow they said understand and debug. >> > >> > Can someone suggest me how to debug it in Wings IDE. >> >> Are those specific bugs that you are supposed to fix or are you to both >> find >> and fix bugs? >> >> > Project have approx 10 files. >> >> Generally speaking speaking this is not so much a matter of tools; if >> there >> is any documentation you can trust reading that is usually the best start; >> reading the code is important, too. >> >> Then you can consider your next steps depending on the "messiness" of the >> code base and the degree of coverage with unit tests. >> >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > There is no documentation provided i have to read the code understand the > flow first. > > > -- > https://mail.python.org/mailman/listinfo/python-list > >
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Project, how to debug Andrew Farrell <amfarrell@mit.edu> - 2015-03-31 15:38 -0500
csiph-web