Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8542 > unrolled thread

RE: Suppressing newline writing to file after variable

Started by"Ellerbee, Edward" <EEllerbee@BBandT.com>
First post2011-06-28 13:32 -0400
Last post2011-06-28 13:32 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  RE: Suppressing newline writing to file after variable "Ellerbee, Edward" <EEllerbee@BBandT.com> - 2011-06-28 13:32 -0400

#8542 — RE: Suppressing newline writing to file after variable

From"Ellerbee, Edward" <EEllerbee@BBandT.com>
Date2011-06-28 13:32 -0400
SubjectRE: Suppressing newline writing to file after variable
Message-ID<mailman.483.1309282386.1164.python-list@python.org>
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@gmail.com] 
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 <EEllerbee@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()

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web