要输出到文件的密码生成器



我有一个学校的大项目,我会得到一个整数的输入,有了这个整数,我会使用随机字符来输出请求的长度。我有一个问题,我会创建一个名为"output.txt"的文件,其中"a"将结果附加到名为 output.txt 的文件中。我想要的是将结果存储到我希望显示的文件中之后。

    print(password_generator(user_input_converted), file=file)

只需调用 print 两次。一次有file,一次没有。

password = password_generator(user_input_converted) 
print(password, file=file)
print(password)

假设password_generator返回密码 - 您的代码似乎暗示了这一点。

使用 open((,如下所示:

passFile = open(file, 'a')
password = password_generator(user_input_converted)
passFile.write(password + 'n')
passFile.close()
print('The password is:', password)

最新更新