写一个函数,使用文件IO,将一个文件的内容复制到另一个文件,并且在复制的过程中,将所有大写字母转换为小写字母,所有小写字母转换为大写字母。
def copy(src,dst):
with open(src,"rt") as r1, open(dst,"wt") as r2:
while True:
text = r1.read(1024 * 1024)
if not text:
break
s = ""
for i in range(len(text)):
if text[i].isupper():
s += text[i].lower()
elif text[i].islower():
s += text[i].lower()
else:
s += text[i]
r2.write(s)
copy("001.txt", "002.txt")