Spell check python source code
Submitted by Christoph on 18 February, 2008 - 00:46
How to spell check Python source code, without wanting to non stop clicking "Ignore" for 'def' or other Python commands?
I have no IDE installed for python, quick Google check didn't give me any nice results, there's something for Emacs, brr.
On a mailing list somebody proposed to write a small script to extract all comments and strings. Though I hate small hacks like this, and would prefer a proper way, like opening my beloved Editor and letting it decided to not treat python code, but just comments and so on...
Well there you go, file extractSpellCheckable.py:
#!/usr/bin/python
# -*- coding: utf8 -*-
"""
Usage:
cat yoursource.py | python extractSpellCheckable.py
"""
import sys
import tokenize
g = tokenize.generate_tokens(sys.stdin.readline) # tokenize the string
for toknum, tokval, _, _, _ in g:
if tokenize.tok_name[toknum] in ['STRING', 'COMMENT']:
print tokval
Use it for whatever you like.