0

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")

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

somelist[...]

6 Comments

Vasquez-Abrams so which should I use where?
You use parens when you want to call a function. You use square brackets when you want to access a sequence or mapping.
So instead of: if symbolList(int(individualPassCounter)) == "A":
I should use: if symbolList(int[individualPassCounter]) == "A"
Is symbolList a function? Is int a sequence?
|

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.