Nhull
Nhull

Reputation: 37

Python: <typeerror> 'str' object is not callable

I'm a noob in python and I'm messing around with it. I have the error in the title on line 20. I read in some sites that the cause could be using some predefined variable but i don't see that problem here (because, probably, I'm a noob). The line of code that is trowing the error is this one "Array[2] = string.uppercase(index1)". Thanks in advance.

Edit:I'm sorry if my code looks confuse/messy, i really have to work on that.

Edit2:

I was trying to create an array of 3 positions and on the third positon do a increment of A to Z and then when it reaches Z, do it again, but now with the range 0 to 9...and then increment the second position (to B) and do it all over again.

#!/usr/bin/python2.7

import string

Array = ['A','A','A']

def Exp():

    index1 = 0
    count = 0

    while Array[1]!=9:
        if Array[2]==9:
            Array[1] = string.uppercase[count]
            count = count + 1
            Array[2]='A'
            index1 = 0
        else:
            while Array[2]!=9:
                Array[2] = string.uppercase[index1]
                index1 = index1 + 1 
                if Array[2] == 'Z':
                    Array[2] = 0
                    while Array[2] < 9:
                        Array[2] = Array[2] + 1                     

Exp()   

Upvotes: 0

Views: 760

Answers (1)

DSM
DSM

Reputation: 353059

string.uppercase is, well, a string of uppercase letters:

>>> import string
>>> string.uppercase
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

And you're trying to call it for some reason:

>>> string.uppercase(3)
Traceback (most recent call last):
  File "<ipython-input-3-757b0bb892f1>", line 1, in <module>
    string.uppercase(3)
TypeError: 'str' object is not callable

I don't understand your code, but maybe you meant to index into it?

>>> string.uppercase[3]
'D'

There are too many things you might be trying to do to guess, though.

(As for why people are having trouble reproducing your code, it looks like you've mixed tabs and spaces, which makes it hard to know what the indentation really is, whether the indentation we're seeing is the indentation you're using, etc. Always use four space indentation instead.

Right now it's not clear how the line which is apparently throwing an error is even reached.)

Upvotes: 1

Related Questions