write and Replace particular line in file

后端 未结 4 1015
刺人心
刺人心 2021-01-19 18:55

I want to replace value of key(i.e db_host, addons_path) with $$$$.

Input text file contains the following:

#         


        
4条回答
  •  醉话见心
    2021-01-19 19:49

    use fileinput module.

    import fileinput
    
    for line in fileinput.input('data.txt',backup='.bak',inplace=1):
        print line.rstrip().replace('Python','Perl') 
        #or print line.replace('Python','Perl'),
    

提交回复
热议问题