<div>Thanks Ben.</div>
<div>&nbsp;</div>
<div>Yeah. I tried that and thought I was doing something wrong. My problem was I was iterating the float or the integer which python didn&#39;t like. <br><br>&nbsp;</div>
<div><span class="gmail_quote">On 11/26/07, <b class="gmail_sendername">Ben Gutierrez</b> &lt;<a href="mailto:bgutierrez@gmail.com">bgutierrez@gmail.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hey Alden,<br><br>Use the int function.&nbsp;&nbsp;E.g., int(&#39;4&#39;).<br><br>If you&#39;re not confident that all the&nbsp;&nbsp;strings are actual numbers,
<br>you&#39;ll need to catch exceptions:<br><br>try:<br>&nbsp;&nbsp; value = int(some_string)<br>except ValueError:<br>&nbsp;&nbsp; value = 0<br><br>Later!<br><br>Ben<br><br>On Nov 26, 2007 11:34 AM, Alden Meneses &lt;<a href="mailto:aldenm@gmail.com">
aldenm@gmail.com</a>&gt; wrote:<br>&gt; Thank you to everyone for your comments and for the extra eyeballs on this<br>&gt; line of code.....<br>&gt;<br>&gt;<br>&gt; elif line(-1) == &#39;F&#39; and line(1) != &#39; &#39;:
<br>&gt;<br>&gt; I blame that on stuffing myself with turkey. :)<br>&gt;<br>&gt; Got a new question - How do you convert text to integer? I want to sum<br>&gt; charges by group and area?<br>&gt;<br>&gt; Thanks in advance,
<br>&gt;<br>&gt; Alden<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt; On 11/23/07, Drew Perttula &lt;<a href="mailto:drewp@bigasterisk.com">drewp@bigasterisk.com</a>&gt; wrote:<br>&gt; &gt; Alden Meneses wrote:<br>
&gt; &gt; &gt; f = open(&#39;H:\xxxx\xxxx\xxxx\9-7-07&#39;)<br>&gt; &gt; &gt; #File is a report that summarizes each account by account group and<br>&gt; &gt; &gt; service area then has the details for each account and Totals before the
<br>&gt; &gt; &gt; next group of accounts.<br>&gt; &gt; &gt; edit = [&quot;GRP&quot;, &quot;AREA&quot;, &quot;CHARGES&quot;]<br>&gt; &gt; &gt; ptype = &quot;NULL&quot;<br>&gt; &gt; &gt; area = &quot;NULL&quot;<br>&gt; &gt; &gt; for line in f:
<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; if line[:12] == &#39;ACCOUNT GROUP&#39;:<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ptype = line[16:]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # The<br>&gt; &gt; &gt; account group starts on the 16th character of the line<br>
&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; elif line[:11] == &#39;SERVICE AREA&#39;:<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; area = line[11:]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#<br>&gt; &gt; &gt; The service area starts on the 11th character of the line<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; elif line(-1) == &#39;F&#39; and line(1) != &#39; &#39;:
<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; edit.append(ptype,area,line[56:66])&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# I wanted to append<br>&gt; &gt; &gt; the edit stack with the variables collected above.<br>&gt; &gt; &gt; f.close()<br>&gt; &gt; &gt; print edit<br>&gt; &gt;
<br>&gt; &gt; The others are correct about line[-1], but in some of these cases you<br>&gt; &gt; could use string methods:<br>&gt; &gt;<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;if line.startswith(&#39;ACCOUNT GROUP&#39;):<br>&gt; &gt; ...<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;elif 
line.startswith(&#39;SERVICE AREA&#39;):<br>&gt; &gt; ...<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;elif line.endswith(&#39;F&#39;) # less important<br>&gt; &gt;<br>&gt; &gt; str.startswith is easier to read and maintain, since it&#39;s got an english
<br>&gt; &gt; name and you don&#39;t have to count the length of your test string.<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; Then, edit.append takes only one argument. I&#39;d guess you wanted to make<br>&gt; &gt; a list of 3-tuples:
<br>&gt; &gt;<br>&gt; &gt;&nbsp;&nbsp; edit = [(&quot;GRP&quot;, &quot;AREA&quot;, &quot;CHARGES&quot;)]&nbsp;&nbsp;# len-1 list of one tuple<br>&gt; &gt; ...<br>&gt; &gt;&nbsp;&nbsp; edit.append((ptype, area, line[56:66]))&nbsp;&nbsp;# append one item to list<br>
&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; Your last line is probably just for testing, but you should be aware of<br>&gt; &gt; the pretty-printing library:<br>&gt; &gt;<br>&gt; &gt; from pprint import pprint
<br>&gt; &gt; ...<br>&gt; &gt; pprint(edit)<br>&gt; &gt;<br>&gt; &gt; [(&#39;GRP&#39;, &#39;AREA&#39;, &#39;CHARGES&#39;),<br>&gt; &gt; (&#39;piggies&#39;, &#39;bay&#39;, &#39;$99.99&#39;),<br>&gt; &gt; (&#39;drew&#39;, &#39;bay&#39;, &#39;$10.00&#39;)]
<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; Baypiggies mailing list<br>&gt; <a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a><br>&gt; To change your subscription options or unsubscribe:
<br>&gt; <a href="http://mail.python.org/mailman/listinfo/baypiggies">http://mail.python.org/mailman/listinfo/baypiggies</a><br>&gt;<br>_______________________________________________<br>Baypiggies mailing list<br><a href="mailto:Baypiggies@python.org">
Baypiggies@python.org</a><br>To change your subscription options or unsubscribe:<br><a href="http://mail.python.org/mailman/listinfo/baypiggies">http://mail.python.org/mailman/listinfo/baypiggies</a><br></blockquote></div>
<br>