Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax recognizer in python

I need a module or strategy for detecting that a piece of data is written in a programming language, not syntax highlighting where the user specifically chooses a syntax to highlight. My question has two levels, I would greatly appreciate any help, so:

  1. Is there any package in python that receives a string(piece of data) and returns if it belongs to any programming language syntax ?
  2. I don't necessarily need to recognize the syntax, but know if the string is source code or not at all.

Any clues are deeply appreciated.

like image 481
PepperoniPizza Avatar asked May 13 '26 19:05

PepperoniPizza


2 Answers

Maybe you can use existing multi-language syntax highlighters. Many of them can detect language a file is written in.

like image 126
Jokester Avatar answered May 16 '26 08:05

Jokester


You could have a look at methods around baysian filtering.

like image 23
kiriloff Avatar answered May 16 '26 07:05

kiriloff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!