[英]Loop prints multiple lines (as intended) but only writes one line to the file
[英]File write is only writing one line when I have encrypted multiple lines
我正在尝试加密 1 个文件并将加密文本从第一个文件保存到另一个文件中。 除了它只将 1 行写入新文件而不是整个文件之外,我已经完成了所有工作。
file1 = open("passwords-plainText", "r")
for line in file1:
file2 = open("encryptedfile.txt", "w")
file2.write(encryptVignere(keyGen(), line))
我正在使用的示例文件如下所示
example
secondexample
new line
this is another new line
输出到我保存的新文件中只写入第一行而不是其余行,即。)
tyawakud
该文件应该看起来像这样......
tyawakud
tqiibwaeeonozp
pttzucfqs
foxnzgjwtmbhnpwhjnapmsfg
你应该只打开file2
一次:
file1 = open("passwords-plainText", "r")
file2 = open("encryptedfile.txt", "w")
for line in file1:
file2.write(encryptVignere(keyGen(), line))
否则你只会继续覆盖它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.