import sys
def replace(file_path, old_str, new_str):
f = open(file_path,'r+')
all_lines = f.readlines()
f.seek(0)
f.truncate()
for line in all_lines:
line = line.replace(old_str, new_str)
f.write(line)
f.close()
if __name__ == "__main__":
file_name = 'test_shs.txt'
src_str ='hunzhuo'
dst_str = '1'
replace(file_name, src_str, dst_str)
src_str = 'qingche'
dst_str ='0'
replace(file_name, src_str, dst_str)