https://www.cnblogs.com/victorm/p/9177665.html
把一些下载的a.py.txt,修改成了a.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
' rename *.txt to *.py '
__author__ = 'Alex He'
import os
with open('a.txt') as read_f,open('.a.txt.swap','w') as write_f:
data=read_f.read() #全部读入内存,如果文件很大,会很卡
data=data.replace('alex','SB') #在内存中完成修改
write_f.write(data) #一次性写入新文件
#os.remove('a.txt')
os.rename('.a.txt.swap','a.py')
read_f.close
write_f.close