2007/3/23, Jay Mutter III &lt;<a href="mailto:jmutter@uakron.edu" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">jmutter@uakron.edu</a>&gt;:<div><span class="gmail_quote"></span><span class="q"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><br><div><span><div>On Mar 23, 2007, at 5:30 AM, Andre Engels wrote:</div><br><blockquote type="cite">2007/3/22, Jay Mutter III &lt;<a href="mailto:jmutter@uakron.edu" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">

jmutter@uakron.edu</a>&gt;:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> I wanted the following to check each line and if it ends in a right
<br>parentheses then write the entire line to one file and if not then<br>write the line to anther.<br>It wrote all of the ) to one file and the rest of the line (ie minus <br>the ) to the other file.</blockquote><div><br>

The line:<br>&nbsp; &nbsp;&nbsp; print &quot;There are &quot;, count, &#39;lines to process in this file&#39;<br>should give you a hint - don&#39;t you think this number was rather high? <br><br>The problem is that if you do &quot;for line in text&quot; with text being a string, it will not loop over the _lines_&nbsp; in the string, but over the _characters_ in the string.
<br><br>The easiest solution would be to replace <br>&nbsp;&nbsp;&nbsp;&nbsp; text = in_file.read()<br>by<br>&nbsp;&nbsp;&nbsp;&nbsp; text = in_file.readlines()<br></div><br></div></blockquote><div><br></div></span><div>Thanks for the response</div><div>Actually the number of lines this returns is the same number of lines given when i put it in a text editor (TextWrangler).
</div><div>Luke had mentioned the same thing earlier but when I do change read to readlines&nbsp;&nbsp;i get the following</div><div><br></div><div><br></div><div>Traceback (most recent call last):</div><div>&nbsp; File &quot;extract_companies.py&quot;, line 17, in ?
</div><div>&nbsp; &nbsp; count = len(text.splitlines())</div><div>AttributeError: &#39;list&#39; object has no attribute &#39;splitlines&#39;</div></div></div></blockquote></span><div><br><br>Ah, yes, there you DO split in lines, but later you don&#39;t. You&#39;ll have to do the same thing twice, that is either:
<br><br><span>text = in_file.readlines()<br>count = len(text) # (instead of count = len(text.splitlines())<br><br>OR<br><br>text = in_file.read()<br></span>for line in text.splitlines(): # (instead of for line in text:)
<br></div><div><span class="e" id="q_1117e63f0c8c0fba_3"><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div><div><span><blockquote type="cite">

<div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">in_filename = raw_input(&#39;What is the COMPLE <br></blockquote></div></blockquote></span>

</div></div></div></blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div><div><span>
<blockquote type="cite"><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">TE name of the file you <br>would like to process?&nbsp;&nbsp;&nbsp;&nbsp;&#39;)<br>

in_file = open(in_filename, &#39;rU&#39;)<br>text = in_file.read()<br>count = len(text.splitlines())<br>print &quot;There are &quot;, count, &#39;lines to process in this file&#39;<br> out_filename1 = raw_input(&#39;What is the COMPLETE name of the file in
<br>which you would like to save Companies?&nbsp;&nbsp;&nbsp;&nbsp;&#39;)<br>companies = open(out_filename1, &#39;aU&#39;)<br>out_filename2 = raw_input(&#39;What is the COMPLETE name of the file in <br>which you would like to save Inventors?&nbsp;&nbsp;&nbsp;&nbsp;&#39;)
<br>patentdata = open(out_filename2, &#39;aU&#39;)<br>for line in text:<br>&nbsp;&nbsp;&nbsp;&nbsp; if line[-1] in &#39;)&#39;:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; companies.write(line)<br>&nbsp;&nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; patentdata.write(line)<br>in_file.close()<br>companies.close

()<br>patentdata.close()<br><br>Thanks<br><br>jay<br>_______________________________________________<br>Tutor maillist&nbsp;&nbsp;-&nbsp;&nbsp;<a href="mailto:Tutor@python.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">

Tutor@python.org </a><br><a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://mail.python.org/mailman/listinfo/tutor</a><br></blockquote></div>

<br><br clear="all"><br>-- <br>Andre Engels, <a href="mailto:andreengels@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">andreengels@gmail.com </a><br>ICQ: 6260644&nbsp;&nbsp;--&nbsp;&nbsp;Skype: a_engels</blockquote>

</span></div></div><br></div></blockquote></span></div></div><div><span class="e" id="q_1117e63f0c8c0fba_5"><br><br clear="all"><br>-- <br>Andre Engels, <a href="mailto:andreengels@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
andreengels@gmail.com</a><br>ICQ: 6260644&nbsp;&nbsp;--&nbsp;&nbsp;Skype: a_engels
</span></div><br clear="all"><br>