类型错误:'list'对象不可调用Python

时间:2017-03-08 02:17:59

标签: python python-3.x

我创建了一个这样的列表:

symbolList = []

何时

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

调用列表,我的脚本停止并给我错误:

TypeError: 'list' object is not callable

如果有人知道为什么答案会受到赞赏。

编辑完整代码:

#!/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 个答案:

答案 0 :(得分:2)

变化

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

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

使用方括号访问列表对象,而不是括号。 您还需要处理IndexError异常

答案 1 :(得分:0)

Parens用于调用函数。方括号用于访问序列和映射。

somelist[...]