Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '(at': 0.03; 'context': 0.04; 'initialize': 0.07; 'pep': 0.07; 'expressions.': 0.09; 'received:209.85.160.174': 0.09; 'received:mail- gy0-f174.google.com': 0.09; '"y"': 0.16; "'w')": 0.16; 'skip:r 50': 0.16; 'to:name:python-list (general)': 0.16; 'this:': 0.16; 'written': 0.17; 'suggest': 0.17; 'variable': 0.21; 'similarly': 0.23; 'code': 0.24; 'keeps': 0.28; 'bit': 0.28; 'message- id:@mail.gmail.com': 0.28; 'closer': 0.30; 'least': 0.31; 'separate': 0.31; 'file.': 0.32; 'to:addr:python-list': 0.34; 'received:209.85.160': 0.34; 'there': 0.34; 'e.g.': 0.34; 'things': 0.34; 'skip:" 10': 0.36; 'open': 0.37; 'some': 0.37; 'subject:Please': 0.37; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.38; 'focused': 0.38; 'something': 0.38; 'think': 0.38; 'else': 0.38; 'should': 0.39; 'data': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.40; "i'd": 0.40; 'where': 0.40; 'skip:r 20': 0.40; '1000': 0.62; 'violation': 0.67; 'voice': 0.69; 'stand': 0.71; '***': 0.73; 'me).': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=mdT+kVk93IHEIYY9m2wxgZ6j6egwrB2/t5np0mxoixs=; b=ZpwYD+dkz2qyZVAyo+capz4bCMd2NtKwd/alcQGXft6DJkJMX5EgU0l4KvkmMtHLtu 2t4rIm0sh2XSSnODvZCIdhXEnkhICGfBzdYMru1GscXsvRCvoa4IstQW5fdcc+rLaMqt Cqaar5+FxkYBrZZqCZO0Zw/y9TQ1tlwTL20fI= MIME-Version: 1.0 Date: Thu, 14 Jul 2011 14:44:04 -0400 Subject: RE: Please critique my script From: Gerald Britton To: "python-list (General)" Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1310669047 news.xs4all.nl 23873 [2001:888:2000:d::a6]:48390 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:9481 For me, there are some things I don't like much. One-character variable names stand out (tend to make the code hard to read). Violation of PEP 8 guidelines, especially wrt spacing. e.g. result.append("%s[%s]%s" % (lastprefix, tails, lastsuffix)) not result.append("%s[%s]%s"%(lastprefix,tails,lastsuffix)) Similarly for many of the assignments and expressions. I see that you initialize count3 at line 39 but don't use it until line 123. I'd suggest that you move the initialization closer to its use. I think that you should move the call to open closer to where you're going to write to the file. In fact, you can do the thing a bit neater with a context manager like this: #------Print the dial-peers to file---- with open(x, 'w') as o: for line in catlist2: figureDpn = count3 + 1000 dpn = str(figureDpn) label = "dial-peer voice " + dpn o.write(label) o.write('\n') ... Note that if you use this approach you don't need a separate call to close(). Also, you can do all the writing in one call to write(), something like this: o.write( label + '\n' + "description *** local outbound dialpeer ***" + '\n' + destpatt + '\n' + "port " + p + '\n' "forward-digits 7" if line[0:3] == y and q == "y" else "" '\n' ) Which keeps the eye focused on the data being written (at least for me). -- Gerald Britton