Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are good ways to make my Python code run first time? [closed]

I'm getting quite a few errors in my code. Consequently, I would like to be able to minimize them at the outset or see as many errors as possible before code execution. Is this possible and if so, how can I do this?

like image 824
Amara Avatar asked Nov 18 '08 18:11

Amara


People also ask

How do you go back to the start of a while loop in Python?

The continue statement in Python returns the control to the beginning of the while loop. The continue statement rejects all the remaining statements in the current iteration of the loop and moves the control back to the top of the loop. The continue statement can be used in both while and for loops.


1 Answers

If you're having problems with syntax, you could try an editor with syntax highlighting. Until you get the feel for a language, simple errors won't just pop out at you.

The simplest form of debugging is just to insert some print statements. A more advanced (and extensible) way to do this would be to use the logging module from the std lib.

The interactive interpreter is a wonderful tool for working with python code, and IPython is a great improvement over the built-in REPL (Read Eval Print Loop).

If you actually want to step through your code, the python debugger is called pdb, which can be called from the command line, or embedded in your code.

If you're used to a fully integrated IDE, I would recommend using Eclipse with pydev, and PyCharm has a great commercial offering, with autocomplete, quick access to docs, and numerous shortcuts, among many other interesting features.

like image 60
JimB Avatar answered Sep 21 '22 15:09

JimB