user1586783
user1586783

Reputation: 1

Does there a tool exists which can help programmer avoid Python NameError?

I am not a native English speaker. When I code with Python, I often make spelling mistakes and get 'NameError' Exceptions. Unit test can solve some problems but not all. Because one can hardly construct test cases which cover all logic. So I think a tool that detect such errors would help me a lot but I searched Google and cannot find it.

Upvotes: 0

Views: 137

Answers (4)

shahjapan
shahjapan

Reputation: 14355

I prefer eclipse with pydev integration for python development projects.

It will solve your purpose and will show you the errors in RED before you run your program. but it requires your project to be properly configured under eclipse as below:

  • Configure Python interpreter after integrating PyDev with eclipse
  • Create / Import your project & set as python pydev project
  • Configure your source folder ( Give information to eclipse that which folders contains python source code under your entire project tree)

You're done & setup now for general python programming setup.

Further more you can integrate your Eclipse/Pydev project with pylint as mentioned by BasicWolf which checks your code quality & bugs on the go while you're coding.

References:

Installing PyDev under Eclise
Eclipse PyDev Integration
Troubleshooting PyDev/PyLint Integration

Upvotes: 1

Atra Azami
Atra Azami

Reputation: 2245

You could get an IDE which helps a bit with autocompletion of names, though not in all situations. PyDev is one such IDE with autocompletion; PyCharm is another (not free).

Using autocomplete is probably your best bet to solve your problem in the long term. Even if you find a tool which attempts to correct such spelling errors, that will not solve the initial problem and will probably just cause new ones.

Upvotes: 0

user2665694
user2665694

Reputation:

pylint can help here. It will report those locations as

E: 2,6: Undefined variable "foo" 

for example.

Upvotes: 0

Zaur Nasibov
Zaur Nasibov

Reputation: 22669

I believe that testing your code via a static analyzer (e.g. pylint) will help a lot.

Another hint: you can use a fancy IDE with smart auto-completion which will reduce the amount of such mistakes.

Upvotes: 3

Related Questions