import random
avchars = ['a','b','c','d','e','f','g']
ra = random.randint(8,24)
rb = random.randint(1,7)
for i in range(ra):
file = open("pass","w")
ac = avchars(rb)
print(ac)
file.write(ac)
file.close()
print("Done")
我想從上面的列表中生成8-24個字符。不過,我收到錯誤:當從列表生成時,不能調用列表對象
TypeError: 'list' object is not callable
應該是'avchars [rb]',而不是'avchars(rb)'。 –
返回'IndexError:列表索引超出範圍' – Finlay
當然,你期望什麼?指數從'0'開始。所以'rb = random.randint(0,6)'。 –