checking for mis-spelled variable names / function names

Chris Rebert clp at rebertia.com
Tue Nov 25 18:27:19 EST 2008


On Tue, Nov 25, 2008 at 3:16 PM, News123 <news123 at free.fr> wrote:
> 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?

PyLint: http://www.logilab.org/857
PyChecker: http://pychecker.sourceforge.net/

I believe they both check for variable name typos, among many other things.

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com

>
> 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list