我试图使用Python的Secrets模块创建x个数量的密码,然后将它们导出到一个新的CSV文件中。我可以创建密码并在屏幕上打印,但当我写入CSV时,字符会被逗号解析出来。(对代码未显示为正确屏蔽表示歉意)
代码:
import secrets
import string
import csv
need = input("Number of passwords:")
need = int(need)
alphabet = string.ascii_letters + string.digits
with open('password.csv', 'w', newline='') as csvfile:
passwriter = csv.writer(csvfile, delimiter=',')
for n in range(need):
password = ''.join(secrets.choice(alphabet) for i in range(10))
print(password)
passwriter.writerow(password)
目前我得到的输出不是我想要的:
它将
string
解释为一个值列表,将其转换为一个值的元组,如下所示:相关问题 更多 >
编程相关推荐