[Baypiggies] Help with code

Max Slimmer max at theslimmers.net
Sat Nov 24 04:33:34 CET 2007

elif line(-1) == 'F' and line(1) != ' ': 

you need to use [] vs () to subscript into line. as the message says line is
not callable.
line[-1] is the last char in line and line[1] is the second char in line.


From: baypiggies-bounces at python.org [mailto:baypiggies-bounces at python.org]
On Behalf Of Alden Meneses
Sent: Friday, November 23, 2007 3:04 PM
To: baypiggies at python.org
Subject: [Baypiggies] Help with code

Hello All,
I am playing with python to work read some text files and help me gather
some data. I have some further reading to do and was hoping some of you can
help point me in the right direction. This is what I have so far.
f = open('H:\xxxx\xxxx\xxxx\9-7-07')
#File is a report that summarizes each account by account group and service
area then has the details for each account and Totals before the next group
of accounts.
edit = ["GRP", "AREA", "CHARGES"]
ptype = "NULL"
area = "NULL"
for line in f:
    if line[:12] == 'ACCOUNT GROUP':
        ptype = line[16:]                                   # The account
group starts on the 16th character of the line
    elif line[:11] == 'SERVICE AREA':
        area = line[11:]                                    # The service
area starts on the 11th character of the line
    elif line(-1) == 'F' and line(1) != ' ': 
        edit.append(ptype,area,line[56:66])        # I wanted to append the
edit stack with the variables collected above.
print edit
I get this error message -
Traceback (most recent call last):
line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Documents and Settings\menesea\My Documents\scripts\readfile.py",
line 11, in <module> 
    elif line(-1) == 'F' and line(1) != ' ':
TypeError: 'str' object is not callable
Thanks in advance,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/baypiggies/attachments/20071123/3282c3b2/attachment.htm 

More information about the Baypiggies mailing list