more descriptive error message than "SyntaxError: invalid syntax"
learning python, coming from a php background. Keeping it short. Is t开发者_C百科here a way to get more descriptive error messages about the syntax error? like in php. Example: print var should give something like "expecting ( " , instead of the standard "SyntaxError: invalid syntax"
Thanks
My advice would be to use a solid IDE. I only tried a few before settling down for Aptana studio which is free (as in freedom) and cross-platform, but I am sure that many other offer similar functionality.
IDE with syntax highlighting will try to parse your code even before runtime, and will signal you any mistake (sometimes they have "false positives" but this is the exception, they are normally very accurate).
Here's a screenshot that illustrate how it works.
This is the wrong code:
And this is the popup that shows when you hover over the red X mark.
As delnan correctly pointed out in the comments to your question, there are a lot of possible "right" things that can go after a print
, hence the verbosity of the popup. Nevertheless I find this feature very useful, as it also shows you methods from unimported objects, variables referenced before assignment and so on and so forth.
HTH!
精彩评论