language analysis to enforce code standards

Jean-Michel Pichavant jeanmichel at sequans.com
Fri Jul 10 14:32:52 CEST 2009


Steven D'Aprano wrote:
> On Fri, 10 Jul 2009 02:06:35 +0000, Jason S. Friedman wrote:
>
>   
>> Hello, I administer the Informatica ETL tool at my company.  Part of
>> that role involves creating and enforcing standards.  I want the
>> Informatica developers to add comments to certain key objects and I want
>> to be able to verify (in an automated fashion) that they have done so.
>>
>> I cannot merely check for non-emptiness; that is trivial to circumvent.
>>   On the other hand, I probably do not need to be able to catch
>> developers who are determined to not create comments.  There are not too
>> many of them and perhaps they will find it is easier to write a (useful)
>> comment than to game the system.
>>
>> Any thoughts on how I might proceed?  Stated plainly, how can I tell
>> when a string more-or-less forms at least one phrase?
>>     
>
> Define "phrase".
>
>
> if len(s) > 0:
>     print "at least one character"
> if len(s.split()) > 0:
>     print "at least one word"
> if len(s.split('\n') > 0:
>     print "at least one line"
>
>
>
>   
You could also verify there are at least N different characters used in 
the sentence:

N = 5 # must contains at least 5 different characters
record = []
for c in s:
    if c not in record:
        record += [c]
if len(record) >= N:
    print "at least %s different characters" % N


Jean-Michel



More information about the Python-list mailing list