Python 3.x 如何合并两个_io.TextIOWrapper文件?

Python 3.x 如何合并两个_io.TextIOWrapper文件?,python-3.x,encryption,Python 3.x,Encryption,我正在用python 3.8制作一个密码生成器项目。它基本上是将密码存储在一个纯文本文件中,并使用GPG对其进行加密(我使用的是Linux)。程序检查是否存在加密文件(这发生在try块中)。如果是这样,加密文件将被解密,然后添加到纯文本文件,最后再次加密。然后,纯文本文件被删除。问题是如何合并加密文件和纯文本文件?代码如下: with open("test.txt","a+") as passwords_file: passwords_fi

我正在用python 3.8制作一个密码生成器项目。它基本上是将密码存储在一个纯文本文件中,并使用GPG对其进行加密(我使用的是Linux)。程序检查是否存在加密文件(这发生在
try
块中)。如果是这样,加密文件将被解密,然后添加到纯文本文件,最后再次加密。然后,纯文本文件被删除。问题是如何合并加密文件和纯文本文件?代码如下:

with open("test.txt","a+") as passwords_file:
        passwords_file.write(account_name_pass + "\n")
        try:
            with open("test.txt.gpg",'r') as decrypted_file:
                subprocess.run('gpg -o test.txt --decrypt test.txt.gpg', shell=True)
                
                # How to merge 2 _io.textIOwrapper files here?
                result = passwords_file.write(decrypted_file)
                print(result)
        except FileNotFoundError:
                subprocess.run('gpg -o test.txt.gpg -e -r michelojordan@protonmail.com test.txt', shell=True)
os.remove("test.txt")
我使用了
write()
函数,但出现以下错误:

TypeError: write() argument must be str, not _io.TextIOWrapper
append()
似乎都不起作用:

AttributeError: '_io.TextIOWrapper' object has no attribute 'append'

我已经找了很久了。非常感谢您的帮助。

passwords\u file.write(decrypted\u file.read())
?我也试过了,但出现了以下错误:UnicodeDecodeError:“utf-8”编解码器无法解码位置0处的字节0x85:无效的起始字节
密码\u file.write(decrypted\u file.read())
?我也尝试过,但出现以下错误:UnicodeDecodeError:“utf-8”编解码器无法解码位置0中的字节0x85:无效的开始字节