views:

232

answers:

7

In C++ I have compiler that tell me if something wrong with my code after refactoring. How to make sure that Python code is at least correct after changes? There may be some stupid error like wrong function name etc. that pretty easy to find in compile time.

Thanks

+2  A: 
  1. use editor / IDE that supports code highlighting. E.g., Notepad++ has word-highlighting feature that I find very useful.

  2. use unit tests

stupid errors will be weeded out first, so I wouldn't worry to much about this type of errors. it's "smart" error you should be afraid of.

SilentGhost
A: 

Eclipse has a good python plugin for doing the syntax highlighting and debugging.

Kieveli
+6  A: 

Looks like PyChecker or pylint are what you're looking for

oggy
is there any IDE or editor in which these integrate nicely?
Sven Hecht
Eclipse/PyDev. That's what I use, and I am a satisfied customer.
RaphaelSP
I think IDLE might have one of those built in (can't remember exactly).
ryan.rousseau
+3  A: 
  1. Use tools such as pylint or PyChecker.

  2. Write unit tests.

Bastien Léonard
A: 

Pylint is almost doing what you are looking for.

You can also force the compilation of your python files. That will show some basic syntax error (it doesn't have all the capability of a c++ compiler)

I've read this article and decided to make an automated build system with pyDev and ant. It does the compilation of the python files and is running the unit tests. Next step is to integrate pylint to that process.

I hope it helps

luc
+1  A: 

Unit test. http://docs.python.org/library/unittest.html

If your tests are written at a reasonable level of granularity, it can be as fast to unit test as it is to run lint or a compiler.

S.Lott
+1  A: 
  • Static analysis (as from the IDE, or from tools like pyLint and pyChecker) is a very quick and effective way to check simple errors, and enforce a common style.
  • Unit tests are a great way to ensure the code stands for its contract.
  • Code reviews and pair programming are one of the best ways to find errors of all sorts, and to spread knowledge in a team.

All of the options require some time, to setup and to execute. However, the gains are tremendous, and far higher than the investment.

Roberto Liffredo