<!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 5.5.2655.35">
<TITLE>String question</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2 FACE="Arial">Hello,</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; I have posted in here a few times asking questions about data filtering. I have part of a code set-up for removing header information and then extracting a column of data (thanks to the python list for help and book recommendations) then writing the column to another file. My question is twofold: How do I maintain a columned format when I write the data to a new file? When I place the data extracting part of my program into the big filter program I receive the error (I am guessing I have an indent problem or syntax):</FONT></P>

<P><FONT SIZE=2 FACE="Arial">Traceback (most recent call last):</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp; File &quot;C:\Python23\filter.py&quot;, line 49, in ?</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; input ()</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp; File &quot;&lt;string&gt;&quot;, line 0&nbsp; </FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; ^</FONT>
<BR><FONT SIZE=2 FACE="Arial">SyntaxError: unexpected EOF while parsing.</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">I have included both the extracting code and the filter code I am trying to place the extracting code in. Thank you very much. </FONT></P>

<P><U><FONT SIZE=2 FACE="Arial">EXTRACTING</FONT></U>
<BR><FONT SIZE=2 FACE="Arial">import string</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">inp = open(&quot;out.txt&quot;,&quot;r&quot;)</FONT>
<BR><FONT SIZE=2 FACE="Arial">outp = open(&quot;out2.txt&quot;,&quot;w&quot;)</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">for line in inp.readlines():</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; words = string.split(line)</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; if len(words) &gt;= 1: </FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outp.write(words[0]) </FONT>
</P>

<P><U><FONT SIZE=2 FACE="Arial">WHOLE FILTER CODE</FONT></U>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; def filterFile(infname,outfname):</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inp = open(infname, &quot;r&quot;) #opens the file lmps for reading</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outp = open(outfname, &quot;w&quot;) #creates the file out.txt for writing</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while 1: #Starts a loop looking for lines with &quot;I&quot; and then writes out all other lines</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text = inp.readline()</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if text ==&quot;&quot;:</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break #if there is no text break from the while loop and continue</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if text[0] ==&quot;I&quot;: #removes all lines starting with I</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; continue</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if text[0] ==&quot;0&quot;: #removes all lines starting 0</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; continue</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outp.write(text) #writes the remaining lines to out.txt</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inp.close() #closes lmps.txt</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outp.close() #closes out.txt</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return </FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; filterFile(&quot;lmps.txt&quot;,&quot;out.txt&quot;) #calls the function to execute it</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; print &quot;Header information has been removed&quot; #tells you that the job has been completed</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; input ()</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; import string</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; inp = open(&quot;out.txt&quot;,&quot;r&quot;)</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; outp = open(&quot;out2.txt&quot;,&quot;r&quot;)</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; for line in inp.readlines():</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; words = string.split(line)</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if len(words) &gt;= 1: </FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outp.write.(words[0])</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Thanks,</FONT>
<BR><FONT SIZE=2 FACE="Arial">Ara</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">&quot;There is something to be learned from a rainstorm. When meeting with a sudden shower, you try not to get wet and run quickly along the road. But doing such things as passing under the eaves of houses, you still get wet. When you are resolved from the beginning, you will not be perplexed, though you still get the same soaking.&quot; - Yamamoto Tsunetomo</FONT></P>

</BODY>
</HTML>