From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/77203 Path: news.gmane.org!not-for-mail From: Hongwen Qiu Newsgroups: gmane.comp.tex.context Subject: Re: Check brackets and parentheses Date: Fri, 06 Jul 2012 20:37:49 +0800 Message-ID: <4FF6DC1D.40307@gmail.com> References: <64C3576E-DF3A-470B-82C9-295690C44AB8@gmail.com> <20120706073844.GN9970@rae.vm.bytemark.co.uk> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0034906057==" X-Trace: dough.gmane.org 1341578284 9249 80.91.229.3 (6 Jul 2012 12:38:04 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 6 Jul 2012 12:38:04 +0000 (UTC) Cc: Pontus Lurcock To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Fri Jul 06 14:38:02 2012 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sn7nN-0001qs-S7 for gctc-ntg-context-518@m.gmane.org; Fri, 06 Jul 2012 14:38:01 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id B4CBD10209; Fri, 6 Jul 2012 14:38:00 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id CIN+WZ0O9V+c; Fri, 6 Jul 2012 14:37:59 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 0CC66101E5; Fri, 6 Jul 2012 14:37:59 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 449F9101E5 for ; Fri, 6 Jul 2012 14:37:58 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id JvnV6ZRnUTTN for ; Fri, 6 Jul 2012 14:37:57 +0200 (CEST) Original-Received: from filter4-ams.mf.surf.net (filter4-ams.mf.surf.net [192.87.102.72]) by balder.ntg.nl (Postfix) with ESMTP id 74BA91018E for ; Fri, 6 Jul 2012 14:37:57 +0200 (CEST) Original-Received: from mail-yx0-f169.google.com (mail-yx0-f169.google.com [209.85.213.169]) by filter4-ams.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id q66CknSm017500 for ; Fri, 6 Jul 2012 14:46:50 +0200 Original-Received: by yenr5 with SMTP id r5so10469963yen.14 for ; Fri, 06 Jul 2012 05:37:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type; bh=rzYvGyMyZ8+cTRb45PrX6+obIzSCrmhnG/ayDTLLzM8=; b=zM/xlAovo8fstJN5I8cAiqT4WyiVDh/c7c84a5JfGWxf9YNoeq7/b8PZ8Zjlp7UAqB 5nBSRqKhQaPRzR/oLUQYxNMTPnGWAFRVjDYS1lroSshRtMTizagJp44Piqs7HfHRDkRF MqvUePJfrg5GmF9hDPLW0zxhUajrdGUXaQja7ZGB1OKHRQLsr2cxlNRFJcGkZDnlRyWI Q1arl85x3yX7yyPVAEXx+HelS89Oy4E/OK2gTANQeFb4OJQwmwYls/5IaY4XJN08/p7P JpND7mGg7LZrBx7R4fVsgJ6en/7nAh10KSiGRrJo5CaCsdeHqh5VjfEiD/1Y9ljRkgeF TFwA== Original-Received: by 10.66.87.2 with SMTP id t2mr14990044paz.22.1341578274257; Fri, 06 Jul 2012 05:37:54 -0700 (PDT) Original-Received: from localhost.localdomain ([122.70.212.117]) by mx.google.com with ESMTPS id rv9sm21813840pbc.43.2012.07.06.05.37.51 (version=SSLv3 cipher=OTHER); Fri, 06 Jul 2012 05:37:52 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 In-Reply-To: <20120706073844.GN9970@rae.vm.bytemark.co.uk> X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=209.85.213.169; country=US; region=CA; city=Mountain View; postalcode=94043; latitude=37.4192; longitude=-122.0574; metrocode=807; areacode=650; http://maps.google.com/maps?q=37.4192,-122.0574&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 01Hv0KNij - ed38eefe80c5 - 20120706 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 192.87.102.72 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.13 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:77203 Archived-At: This is a multi-part message in MIME format. --===============0034906057== Content-Type: multipart/alternative; boundary="------------030800080002060208090200" This is a multi-part message in MIME format. --------------030800080002060208090200 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 07/06/2012 03:38 PM, Pontus Lurcock wrote: > brace-lint.py > > > #!/usr/bin/python > > import sys > > '''Count opening and closing braces in a file.''' > > def count(filename, opening, closing): > print opening, closing > f = open(sys.argv[1], 'r') Shouldn't this line be f = open(filename, 'r') otherwise the 'filename' parameter will not be used > braces = 0 > i = 1 > last_zero = -1 > for line in f.readlines(): > braces += line.count(opening) > braces -= line.count(closing) > if braces==0: last_zero = i > i += 1 > f.close() > print last_zero > > count(sys.argv[1], '{', '}') > count(sys.argv[1], '[', ']') > count(sys.argv[1], '\\start', '\\stop') --------------030800080002060208090200 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
On 07/06/2012 03:38 PM, Pontus Lurcock wrote:
brace-lint.py

#!/usr/bin/python

import sys

'''Count opening and closing braces in a file.'''

def count(filename, opening, closing):
    print opening, closing
    f = open(sys.argv[1], 'r')
Shouldn't this line be
         f = open(filename, 'r')
otherwise the 'filename' parameter will not be used
    braces = 0
    i = 1
    last_zero = -1
    for line in f.readlines():
        braces += line.count(opening)
        braces -= line.count(closing)
        if braces==0: last_zero = i
        i += 1
    f.close()
    print last_zero

count(sys.argv[1], '{', '}')
count(sys.argv[1], '[', ']')
count(sys.argv[1], '\\start', '\\stop')


--------------030800080002060208090200-- --===============0034906057== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ --===============0034906057==--