checking for mis-spelled variable names / function names

News123 news123 at free.fr
Wed Nov 26 00:16:36 CET 2008


Hi,

Let's imagine following code

def specialfunc():
	print "very special function"

name= getuserinput()
if name == 'one_name_out_of_a_million':
	print "Hey your name '%s' is really rare" % namee
        specialfunk()

my python script could survive thousands of runs before falling into
the mis-spelled code section. ('namee' instead of 'name' and
'specialfunck()' instead of 'specialfunc()'
I know that good designers should always test their code and have
complete code coverage, before releasing their beasts into the wild, but
in my experience this is not always what happens.

I fell already over quite of my own sins, but also over typoes of other
python authors.

Is there any way in python to check for mis-spelled variable / function
names?


In perl for example 'use strict;' would detect bad variable names,
though it wouldn't detect calls to undeclared functions.

I am aware, that there is absolutely valid (and useful) python code with
 undefined functions / variable names.

However for the scripts that I write I would prefer to identify as many
typoes as possibe already when trying to run the script the first (and
not the millionth) time.

Do you have ideas suggestions?
Are there any 'lint' like tools trying to analyze python code for
potential stupidities?

If yes, what would be 'the' way to add these tools / modules at )least
during the development cycle) to the scripts.


thanks in advance for any thoughts / suggestions.


bye


N



More information about the Python-list mailing list