Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check compilation errors in python?

#!/usr/bin/python  
str = "this"  
if(1):  
  print "Hi"  
else:  
  print str.any_random_function()  

This doesn't fail when I run the program. I tried py_compile but that didn't indicate the error in the else loop either. Now how can I compile the program and detect errors reliably in python code?

like image 809
stacka Avatar asked Jan 22 '10 13:01

stacka


2 Answers

I think your best bet would be pylint.

like image 177
Geo Avatar answered Nov 16 '22 03:11

Geo


Python is a dynamic language, so you can't simply check for compiling errors like in static languages (C/C++/Java). If you assign str.any_random_function, the above code would be correct (okay that's a bad example...).

I'd suggest you to use PyDev for Eclipse which automatically finds many common problems in your code, like missing functions/modules etc. It also supports pylint (optional).

like image 35
AndiDog Avatar answered Nov 16 '22 04:11

AndiDog