Text19. Дан текстовый файл. Заменить в нем все прописные русские буквы на строчные, а все строчные — на прописные.

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

import codecs

file1 = "text19.txt"
print("Read from:",file1)
file2 = "text19_2.txt"
print("Write to:",file2)

ru_Lower = u"абвгдежзийклмнопрстуфхцчшщъыьэюя"
ru_Upper = u"АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"

try:
with codecs.open(file1, 'r', 'utf-8') as infile, \
codecs.open(file2, 'w', 'utf-8') as outfile:
for line in infile:
s_new = ""
for c in line:
if c in ru_Lower:
c = c.upper()
elif c in ru_Upper:
c = c.lower()
s_new += c
outfile.write(s_new)
print(s_new)

except IOError:
print('Open error: ',file1)