python - 如何使用.join?

标签 python error-handling passwords python-3.8 iterable

我已经在google上阅读过相关内容。我不明白这意味着什么(只能加入iterable)。请告诉我如何解决此问题,我应该从何处了解更多信息

import random
letters = ['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', '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']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']

print("Welcome to the PyPassword Generator!")
nr_letters= int(input("How many letters would you like in your password?\n")) 
nr_symbols = int(input(f"How many symbols would you like?\n"))
nr_numbers = int(input(f"How many numbers would you like?\n"))

for letter in letters:
    letter_in_pass = random.sample(letters,nr_letters)

for symbol in symbols:
    symbol_in_pass = random.sample(symbols, nr_symbols)

for number in numbers:
    number_in_pass = random.sample(numbers, nr_numbers)
    
password_list = (letter_in_pass + symbol_in_pass + number_in_pass)
random_password = random.shuffle(password_list)


final_password = ' '.join(random_password)
print(final_password)



the error is this:
File "/Users/angadsinghbedi/Desktop/python/JFF.py", line 24, in <module>
    final_password = ' '.join(random_password)
TypeError: can only join an iterable
谢谢

最佳答案

Random.Shuffle运行后会在状态上返回None。
要解决您的错误,您应该在join函数中使用password_list变量。随机播放功能不会返回列表,而是会更改内存中的列表。

final_password = ' '.join(password_list)

关于python - 如何使用.join?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65339637/

相关文章:

python - 在 AWS Sagemaker 中使用 python pandas 从 S3 存储桶中读取大型 csv

python - Pandas :加入 'on' 失败

python - 如何正确设置此 API 调用的格式?

javascript - 处理和跟踪 JavaScript 错误

security - 密码自加密可行吗?

python - 在 Python 中使用 MySQLdb 进行 Windows 身份验证

ios - 播放结束后无法重播视频

error-handling - 尝试忽略我的tcl命令中的错误

java - 在亚洲语言(韩语、日语、中文)的 Java swing (JPasswordField) 中设置密码不起作用

android - proguard 防止逆向工程的安全性如何?