<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7655.11">
<TITLE>Suppressing newline writing to file after variable</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><FONT SIZE=2 FACE="Arial">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. </FONT></P>
<P><FONT SIZE=2 FACE="Arial">Here is my code snippet:</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">count=0</FONT>
<BR><FONT SIZE=2 FACE="Arial">o = open('dialpeers.txt', 'w')</FONT>
<BR><FONT SIZE=2 FACE="Arial">for line in open('final.txt', 'r'):</FONT>
<BR><FONT SIZE=2 FACE="Arial"> figureDpn = count + 1000</FONT>
<BR><FONT SIZE=2 FACE="Arial"> dpn = str(figureDpn)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> label = "dial-peer voice " + dpn</FONT>
<BR><FONT SIZE=2 FACE="Arial"> o.write(label)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> o.write('\n')</FONT>
<BR><FONT SIZE=2 FACE="Arial"> destpatt = "destination-pattern " + line + "...."</FONT>
<BR><FONT SIZE=2 FACE="Arial"> o.write(destpatt)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> o.write('\n')</FONT>
<BR><FONT SIZE=2 FACE="Arial"> o.write("description *** local outbound dialpeer ***")</FONT>
<BR><FONT SIZE=2 FACE="Arial"> o.write('\n')</FONT>
<BR><FONT SIZE=2 FACE="Arial"> port = "port " + p</FONT>
<BR><FONT SIZE=2 FACE="Arial"> o.write(port)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> o.write('\n')</FONT>
<BR><FONT SIZE=2 FACE="Arial"> o.write('\n')</FONT>
<BR><FONT SIZE=2 FACE="Arial"> count = count + 1</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Output:</FONT>
<BR><FONT SIZE=2 FACE="Arial">dial-peer voice 1000</FONT>
<BR><FONT SIZE=2 FACE="Arial">destination-pattern 252200</FONT>
<BR><FONT SIZE=2 FACE="Arial">....</FONT>
<BR><FONT SIZE=2 FACE="Arial">description *** local outbound dialpeer ***</FONT>
<BR><FONT SIZE=2 FACE="Arial">port 0/1</FONT>
</P>
<BR>
<P><FONT SIZE=2 FACE="Arial">Desired Output:</FONT>
<BR><FONT SIZE=2 FACE="Arial">dial-peer voice 1000</FONT>
<BR><FONT SIZE=2 FACE="Arial">destination-pattern 252200....</FONT>
<BR><FONT SIZE=2 FACE="Arial">description *** local outbound dialpeer ***</FONT>
<BR><FONT SIZE=2 FACE="Arial">port 0/1</FONT>
</P>
<BR>
<P><FONT SIZE=2 FACE="Arial">I've just started with Python 3 weeks ago, so my code is poortly written. I would appreciate any suggestions to improve.</FONT></P>
<P><FONT SIZE=2 FACE="Arial">Ed Ellerbee</FONT>
</P>
<BR>
</BODY>
</HTML>