我有一个学校的大项目,其中我将获得一个整数的输入,并使用该int,我将使用随机字符来输出请求的长度。我有一个问题,我会创建一个名为" output.txt“的文件,用"a”表示将结果追加到名为output.txt的文件中。我想要的是在结果存储到我想要显示的文件中之后。
print(password_generator(user_input_converted), file=file)
发布于 2019-04-29 00:54:43
只需调用print两次。一次使用file
,一次不使用。
password = password_generator(user_input_converted)
print(password, file=file)
print(password)
假设password_generator
返回密码--您的代码似乎暗示了这一点。
发布于 2019-04-29 01:34:14
使用open(),如下所示:
passFile = open(file, 'a')
password = password_generator(user_input_converted)
passFile.write(password + '\n')
passFile.close()
print('The password is:', password)
https://stackoverflow.com/questions/55892537
复制相似问题