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