0

I am trying to run this code where I use regular expression and dict(). I need to put the matching elements into the right list,but I get the error.TypeError: 'list' object is not callable. Can anyone tell me what am I doing wrong here.

dir='newDSSP'
for tname in os.listdir(dir):
    file=dir+os.sep+tname
    ndfile=open(file)
    tname=dict()
    tname.setdefault('A',[[],[]])
    tname.setdefault('B',[[],[]])
    tname.setdefault('C',[[],[]])
    tname.setdefault('D',[[],[]])
    for ndline in ndfile:
        t=re.match(r'(\s+|\S+)+\t\w+\t(\w)\t(\w)\t(\w|\s)', ndline)
        k=t.group(2)
        if k =='A':

            tname['A'](0).append(t.group(3))<--- **#Error here**
            tname['A'](1).append(t.group(4))
        elif k =='B':

            tname['B'](0).append(t.group(3))
            tname['B'](1).append(t.group(4))
        elif k =='C':

            tname['C'](0).append(t.group(3))
            tname['C'](1).append(t.group(4))
        elif k =='D':

            tname['D'](0).append(t.group(3))
            tname['D'](1).append(t.group(4))
    ndfile.close()

2 Answers 2

8

You have

tname['A'](0).append(t.group(3))

but isn't tname['A'] a list containing two lists? In that case, you want

tname['A'][0].append(t.group(3))
Sign up to request clarification or add additional context in comments.

1 Comment

OK,I get it,master!Thanks for your kind help!
1

x() is always a function call, so something like tname['C'](0) is trying to call tname['C'] as a function with parameter 0. Perhaps you intended square brackets for a list index?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.