这段代码的目标是在回答了几个命令提示问题之后,生成一组随机的密码,将这些密码保存到文本文档中,供以后查看/编辑。我遇到了一个文本文档实际上没有被编辑的问题,在阅读了一些类似的问题之后,我做了一些调整。不过我还是需要帮助!
for password in passwords:
with open('SavedPasswords.rtf' , 'a') as f:
#the following loops create the password(s) and print them to console
if special_chars == "YES" :
for pwd in range(amount):
passwords = ''
for c in range(length):
passwords += random.choice(chars)
print(passwords)
f.write(passwords)
elif special_chars == "NO" :
for pwd in range(amount):
passwords = ''
for c in range(length):
passwords += random.choice(chars2)
print(passwords)
f.write(passwords)发布于 2022-06-15 01:56:58
当我重新构建你的案子时,我就是这么做的:
import random
import string # For string module
passwords = ["", "", "", ""]
special_chars = "YES" # Just for testing
amount = 2
length = 10
# Use the string module to get all ascii char
with_punctuation = string.ascii_letters + string.punctuation
without_punctuation = string.ascii_letters
for password in passwords:
with open('SavedPasswords.rtf' , 'a') as f:
if special_chars == "YES" :
for pwd in range(amount):
passwords = ''
for c in range(length):
passwords += random.choice(with_punctuation)
print(passwords)
f.write(passwords + "\n") # Add this to separate them, I think a csv is better!
elif special_chars == "NO" :
for pwd in range(amount):
passwords = ''
for c in range(length):
passwords += random.choice(without_punctuation)
print(passwords)
f.write(passwords + "\n")你没有说出你到底做了什么,所以这是我所能做的。
https://stackoverflow.com/questions/72625016
复制相似问题