I have a input text file as follows, this is saved as 12.txt:
[(442, 165), (442, 184), (487, 165), (487, 184)],english
My aim is to remove all the special characters from this file and overwrite it : I am using below python script :
import os
import numpy as np
import math
import cv2 as cv
#path = '/media/D/code/OCR/text-detection-ctpn/data/mlt_english+chinese/image'
gt_file = '12.txt'
with open(gt_file, 'r+') as f:
for line in f.readlines():
line = line.replace("[", "")
line = line.replace("(", "")
line = line.replace(")", "")
line = line.replace("]", "")
line = line.replace(" ", "")
f.write(line)
However it gives me this output:
[(234, 162), (234, 183), (307, 162), (307, 183)],english 234,162,234,183,307,162,307,183,english
I dont want the output to be appended as it is as shows above I want the output to overwrite 12.txt. Filethat is 12.txt after running python script should look like this:
234,162,234,183,307,162,307,183,english
I have referred Python replace and overwrite instead of appending but there is some thing I am missing