Python 在txt文本指定行 添加字符串

file = open("*.txt",'r')

content = file.read()
file.close()
pos = content.find( "2.4G MAC address" )
if pos != -1:
   content = content[:pos] + "\n" +"=========================================================================" + "\n"+"*****************" + "\n" + "**** P A S S ****"+"\n"+"*****************"+"\n" + content[pos:]
   file = open( "*.txt", "w" )
   file.write( content )
   file.close()
posted @ 2021-11-08 13:20  江南王小帅  阅读(540)  评论(0)    收藏  举报