Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'newbie': 0.03; 'formatting': 0.07; 'written.': 0.07; 'python': 0.08; 'newline': 0.09; 'message-----': 0.12; 'subject:file': 0.13; 'wrote:': 0.15; "'w')": 0.16; 'condense': 0.16; 'inserting': 0.16; 'router.': 0.16; 'subject:variable': 0.16; 'subject:writing': 0.16; 'thru': 0.16; 'too)': 0.16; 'edward': 0.16; 'cc:addr:python- list': 0.16; 'pm,': 0.16; 'thanks!': 0.17; 'suggest': 0.17; 'file)': 0.19; 'cc:': 0.19; 'issue.': 0.19; 'seems': 0.20; 'variable': 0.21; 'cc:2**0': 0.21; 'cc:no real name:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'unsure': 0.23; 'tue,': 0.23; 'code': 0.24; '(or': 0.25; 'hall': 0.26; 'string': 0.26; 'function': 0.26; 'fine': 0.26; "i'm": 0.27; 'all,': 0.28; 'start,': 0.29; 'fix': 0.29; 'cc:addr:python.org': 0.30; 'subject:': 0.30; 'researching': 0.30; 'file.': 0.32; "i'll": 0.33; 'skip:" 20': 0.33; 'list.': 0.33; "i've": 0.33; 'sent:': 0.34; '\xa0\xa0\xa0': 0.34; 'example,': 0.35; 'thank': 0.35; 'question': 0.35; 'from:': 0.36; 'skip:o 20': 0.36; 'file': 0.36; 'issue': 0.37; 'instead.': 0.37; 'pull': 0.37; 'some': 0.37; 'listed': 0.37; 'but': 0.37; 'could': 0.37; 'using': 0.37; 'subject:: ': 0.38; 'problems': 0.38; 'web,': 0.39; 'where': 0.40; 'more.': 0.61; '1000': 0.62; 'here': 0.66; 'here.': 0.66; 'voice': 0.69; 'june': 0.69; 'cisco': 0.73; '12:18': 0.84; '2.7.': 0.84; 'perfect,': 0.84; 'wildcard': 0.84 X-Server-Uuid: 7C9F3A3D-0A58-4F63-8FA5-251C0509CB4B X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Subject: RE: Suppressing newline writing to file after variable Date: Tue, 28 Jun 2011 13:32:48 -0400 In-Reply-To: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Suppressing newline writing to file after variable Thread-Index: Acw1rxCI3QX6muYoTvCbjtreK9MkYgACWW4w References: <77AE044B1BF3944FAE2435F395F11B4B016A2910@clt-exmb02.bbtnet.com> From: "Ellerbee, Edward" To: "Noah Hall" X-OriginalArrivalTime: 28 Jun 2011 17:32:50.0334 (UTC) FILETIME=[673043E0:01CC35B9] X-CFilter-Loop: Reflected X-WSS-ID: 6214CE331ZO749156-01-01 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org 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: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1309282386 news6.xs4all.nl 4365 [2001:888:2000:d::a6]:49545 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:8542 Thank you! That works perfect, I'll have to look into string formatting more.=20 My next issue to solve I've been researching is: How to condense a group of numbers to a wildcard list. For example: 252205 252206 252208 252220 252221 252222 252223 919745 919725 919785 704770 thru 704799 (all numbers listed individually in a file) Condense to: 25220[568] 25222[0-3] (or 25222[0123] is fine too) 9197[248]5 7047[0-9][0-9]=20 Any recommendations on where to start, a method or function to research? Thanks! Edward Ellerbee -----Original Message----- From: Noah Hall [mailto:enalicho@gmail.com]=20 Sent: Tuesday, June 28, 2011 12:18 PM To: Ellerbee, Edward Cc: python-list@python.org Subject: Re: Suppressing newline writing to file after variable On Tue, Jun 28, 2011 at 5:05 PM, Ellerbee, Edward = wrote: > Hi all, newbie question here. I'm using python 2.7. I've built my=20 > first program to pull some info off the web, process it, and build=20 > dialpeers for a cisco router. I have 2 problems - the first is the=20 > formatting of printing the gathered information to a file. It seems to = > be inserting a new line after the variable is written. I've searched=20 > the web, but unsure of which method could fix this issue. > > Here is my code snippet: > > count=3D0 > o =3D open('dialpeers.txt', 'w') > for line in open('final.txt', 'r'): > =A0=A0=A0 figureDpn =3D count + 1000 > =A0=A0=A0 dpn =3D str(figureDpn) > =A0=A0=A0 label =3D "dial-peer voice " + dpn > =A0=A0=A0 o.write(label) > =A0=A0=A0 o.write('\n') > =A0=A0=A0 destpatt =3D "destination-pattern " + line + "...." Try line.rstrip() instead. It'll remove all newlines. Also, I suggest = you use string formatting, for example, >>>destpatt =3D "destination-pattern %s...." % line.rstrip()