Apr-28-2018, 05:33 AM
i have found that the "file" command in Ubuntu Linux is doing a poor job at recognizing Python files. i ran it through all files in "/usr" that end in ".py" (12661 files) and many of them (1391) were not recognized by the "file" command. in a few cases, the file contained all comments, so interpreting it as various other languages would produce no errors. in most cases there were some various Python statements and valid Python code. in all cases i'd say all the experienced coders here could quickly recognize it as Python. maybe, some of the smaller ones could be error free in some other languages.
back when i was in college (mainframe batch card days) someone claimed they could write a program that would read source code and figure out if it was Fortran or PL/1 (and later added COBOL to his list) and run the proper compiler. i then wrote a program that worked under either the Fortran compiler or the PL/1 compiler (and did the same thing). he gave up on his project.
all i need right now is the test "is this file valid as Python". if it also looks like something else, i don't care. i only want to know if it is valid as Python. is there some way to do this without running the code? i'm not concerned about erroneous code. that can be answered either way and does not matter.
back when i was in college (mainframe batch card days) someone claimed they could write a program that would read source code and figure out if it was Fortran or PL/1 (and later added COBOL to his list) and run the proper compiler. i then wrote a program that worked under either the Fortran compiler or the PL/1 compiler (and did the same thing). he gave up on his project.
all i need right now is the test "is this file valid as Python". if it also looks like something else, i don't care. i only want to know if it is valid as Python. is there some way to do this without running the code? i'm not concerned about erroneous code. that can be answered either way and does not matter.