[Baypiggies] Help with code

Shiqi Yang shiqiyang at shiqiyang.com
Sat Nov 24 00:12:28 CET 2007


Hi, 

  I'm not an expert, but seems changing the line(-1) to line[-1] and line(1)
to line[1] in your code would help in some sense.

 

Shiqi

 

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.
f.close()
print edit

 

 

I get this error message -

 

Traceback (most recent call last):
  File
"C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
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,

Alden

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


More information about the Baypiggies mailing list