Personal tools
You are here: Home Weblog Archive 2007 April

Entries For: April 2007

2007-04-28

Write nicer Python code

Filed Under:

Starting from the basic facts:

  • you can't always code in pair
  • you don't want to compile & tests to check that is fine in the last few line you have just written
  • you want to write nice python code
  • you want to improve the way you write python

It exists a few very interesting softwares that can help you.

Here is a list of the one I am using really often:

PyFlakes - http://www.divmod.org/projects/pyflakes

PyLint - http://www.logilab.org/view?rql=Any%20X%20WHERE%20X%20eid%20857

These two are nice also but not as good as the previous one:

PyMetrics - http://sourceforge.net/projects/pymetrics

PyChecker - http://pychecker.sourceforge.net/
 
These tool are directly linked to my favourite editor VI:

command Pyflakes :call Pyflakes()
function! Pyflakes()
    let tmpfile = tempname()
    execute "w" tmpfile
    execute "set makeprg=(pyflakes\\ " . tmpfile . "\\\\\\|sed\\ s@" . tmpfile ."@%@)"
    make
    cw
endfunction


command Pylint :call Pylint()
function! Pylint()
setlocal makeprg=(echo\ '[%]';\ pylint\ %)
setlocal efm=%+P[%f],%t:\ %#%l:%m
silent make
cwindow
endfunction


And better each time you save your python file in vim , I check for wrong imports with Pyflakes with:

autocmd BufWrite *.{py} :call Pyflakes()



Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: