开发者

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?


I think your best bet would be pylint.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜