Dylan Haigh
Dylan Haigh

Reputation: 53

Type Error: 'list' object not callable Python

I have created a list like this:

symbolList = []

When

if symbolList(int(individualPassCounter)) == "A":

Calls the list, my script stops and gives me the error:

TypeError: 'list' object is not callable

If anyone knows why an answer would be appreciated.

Edit Full Code:

#!/usr/local/var/homebrew/linked/python3/bin/python3
import random

data = ['a', 'b', 'c', 'd' ,'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

dataNumber = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']

dot = '.'

passAmount = input("Input number of passwords:\t")

symbolAmount = input("\nInput number of symbols within a password:\t")

print("\nFor an uppercase letter enter 'A'")
print("\nFor a lowercase letter enter 'a'")
print("\nFor a number enter '1'")
print("\nFor a symbol enter '.'")

symbolList = []

symbolAmountCounter = 0

while symbolAmountCounter < int(symbolAmount):
    symbolType = input("\nInput" + str(symbolAmountCounter+1)+". symbol type:\t")
while True:
    if symbolType == "A" or symbolType == "a" or symbolType == "1" or symbolType == ".":
        symbolList.append(symbolType)
        break
    else:
        print("\nWrong type selected, try again.")
        symbolType = input("\nInput" + str(symbolAmountCounter+1)+ ". symbol type:\t")
symbolAmountCounter += 1

def checkDuplicate(passwordListFinished, individualPassword):
    for x in passwordListFinished:
        if (x == individualPassword):
            return False

passwordListFinished = []

finalPasswordCounter = 0

for finalPasswordCounter in range(int(passAmount)):
    individualPass = []
    individualPassCounter = 0
    for individualPassCounter in range(len(symbolList)):
        if symbolList(int(individualPassCounter)) == "A":
            symbolRandomSelect = random.choice(data).upper()
            individualPass.append(symbolRandomSelect)
        elif symbolList(int(individualPassCounter)) == "a":
            symbolRandomSelect = random.choice(data)
            individualPass.append(symbolRandomSelect)
        elif symbolList(int(individualPassCounter)) == "1":
            symbolRandomSelect = random.choice(dataNumber)
            individualPass.append(symbolRandomSelect)
        elif symbolList(int(individualPassCounter)) == ".":
            symbolRandomSelect = random.choice(dot)
            individualPass.append(symbolRandomSelect)

individualPassword = ''.join(str(x) for x in individualPass)

if len(passwordListFinished) == 0:
    passwordListFinished.append(individualPassword)
else:
    if checkDuplicate(passwordListFinished, individualPassword):
        passwordListFinished.append(individualPassword)

finalPasswordCounter += 1

f = open("/Users/dylanrichards/Desktop/passwordlist.txt", 'w')
i = 0

while i < len(passwordListFinished):
    f.write("\n" + passwordListFinished)
    f.close()
    print("Passwords Generated")

Upvotes: 0

Views: 194

Answers (2)

Yonas Kassa
Yonas Kassa

Reputation: 3720

change

if symbolList(int(individualPassCounter)) == "A":

to

if symbolList[int(individualPassCounter)] == "A":

list objects are accessed with square brackets, not with parentheses. You also need to handle IndexError exceptions

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799420

Parens are used for calling functions. Square brackets are used for accessing sequences and mappings.

somelist[...]

Upvotes: 0

Related Questions