Suppressing newline writing to file after variable

Ellerbee, Edward EEllerbee at BBandT.com
Tue Jun 28 13:32:48 EDT 2011


Thank you!

That works perfect, I'll have to look into string formatting more. 

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] 

Any recommendations on where to start, a method or function to research?

Thanks!

Edward Ellerbee



-----Original Message-----
From: Noah Hall [mailto:enalicho at gmail.com] 
Sent: Tuesday, June 28, 2011 12:18 PM
To: Ellerbee, Edward
Cc: python-list at python.org
Subject: Re: Suppressing newline writing to file after variable

On Tue, Jun 28, 2011 at 5:05 PM, Ellerbee, Edward <EEllerbee at bbandt.com> wrote:
> Hi all, newbie question here. I'm using python 2.7. I've built my 
> first program to pull some info off the web, process it, and build 
> dialpeers for a cisco router. I have 2 problems - the first is the 
> 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 
> the web, but unsure of which method could fix this issue.
>
> Here is my code snippet:
>
> count=0
> o = open('dialpeers.txt', 'w')
> for line in open('final.txt', 'r'):
>     figureDpn = count + 1000

>     dpn = str(figureDpn)
>     label = "dial-peer voice " + dpn
>     o.write(label)
>     o.write('\n')
>     destpatt = "destination-pattern " + line + "...."

Try line.rstrip() instead. It'll remove all newlines. Also, I suggest you use string formatting, for example,
>>>destpatt = "destination-pattern %s...." % line.rstrip()




More information about the Python-list mailing list