File47. Даны два файла одного и того же типа. Добавить к первому файлу содержимое второго файла, а ко второму файлу — содержимое первого.

Решение на Python 3:

# -*- coding: utf-8 -*-
import sys

file1 = "file47_1.txt"
file2 = "file47_2.txt"

try:
with open(file1, "rb") as f_in:
data1 = f_in.read()

with open(file2, "rb") as f_in:
data2 = f_in.read()

with open(file1, "ab") as f_out:
f_out.write(data2)

with open(file2, "ab") as f_out:
f_out.write(data1)

except:
print("Error: ", sys.exc_info())