Not able to replace the string in file
with open("dc_setup.tcl",'r+') as file:
for line in file:
if str0 in line:
line1=line
print(line1)
contents=file.read()
contents=contents.replace(line1,new_str)
file.seek(0)
file.truncate()
file.write(contents)
I expect the code to replace string in that file , but I'm getting empty file
new_str. Second, ifnew_stris a valid string, you can check the contents byprint(contents)first before & after the replacement.