Python code is incorrectly recognized as Ruby

Back to Programming Languages forum

cescapa     2015-05-15 22:21:50
User avatar

Is there a way that we can help the interpreter recognize Python (3) code accurately? What does it expect the first line to be? Thanks

Rodion (admin)     2015-05-17 06:38:29
User avatar

Hi!

Thanks for your question! Currently the "algorithm" of recognizing the languages is stupid enough. It looks like this. You see, it just tries to detect the language by few keywords and usual thing to mistake Python for Ruby is something related with end keyword, I'm afraid. :(

So you can either find a way to write your sources in some different manner - or suggest some change to this primitive recognition-code so we can improve it together :)

cescapa     2015-05-19 07:23:28
User avatar

Hi Rodion, thanks so much for the quick reply.

If you can modify the code detector to find this string in Python, it would be great help:

#!/usr/bin/python 

That would never be triggered by any other language. Please put this check towards the top of the language detection logic.

And can I ask you a favor. I made a mistake when I typed the title of this forum entry. Please change it to:

"Python code is incorrectly recognized as Ruby"

Thanks much Rodion
Carlos

Vladimir Skvortsov     2016-09-02 14:07:41
User avatar

Also the interpreter recognize mistakenly Ruby language. It sees Python code if there wasn't announce tag "def".

Please login and solve 5 problems to be able to post at forum