I want to replace value of key(i.e db_host, addons_path) with $$$$.
db_host
addons_path
$$$$
Input text file contains the following:
#
What about something like this ?
def replace_string(s): s = s.replace('db_host','$$$$') return s with open('test.txt','r') as fo: line = fo.read() # you could use strip() or split() additionally new_string = replace_string(line)