import os
for i in os.listdir('目录名'):
f=open(i,'a') # 追加的话这里要用'a',要不就覆盖了
f.write('hello world')
f.close()
import glob
def doappend(filename, tobeappend='\nhello world\n'):
with open(filename,'a') as handle:
handle.write(tobeappend)
def procdir(dir):
map(doappend, glob.glob(os.path.join(dir,'*.py')))
if __name__ == '__main__':
procdir(r'E:\workspace\testpy')
用循环啊