开发者

Python mistype prevention

I often mist开发者_如何学JAVAype names of variables in python, and python is dynamic, so i detect it only when incorrect code runs. How can i prevent mistyping in python?


Use an editor: Eclipse + PyDev has a good detection system for these kinds of errors. Also tools as pychecker can help


You can set highlight words in most good editors like vim and emacs.

Vim: http://vim.wikia.com/wiki/Highlight_multiple_words Emacs: http://nschum.de/src/emacs/highlight-symbol/


Try pyflakes. It can find many errors in Python programs, including mistyped variables.

http://pypi.python.org/pypi/pyflakes


I would suggest running all your files through various static code checkers.

Here is a list of those I use for everyday programming:

  • flake8 (pip install flake8) and flake8-bugbear (pip install flake8-bugbear)
  • pylint (pip install pylint)
  • black (pip install black)

Some people also like:

  • pylama

These tools will check style and find syntax errors like misspelled variable names.

Some of them are quite opinionated when it comes to style (e.g. black) but can be configured to ignore certain style mismatches.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜