ArmanPython
6 subscribers
2 photos
28 files
10 links
Transfer python files
Download Telegram
import os
import re
change_list = ("merge_series(", "merge_parallel(")
myfile = open("cmos12lpplus.compare.rs", "r")

tmp_str = ""
out = ""
found = False
count = 0
com = ""

for line in myfile.readlines():

pattern = re.compile(r"(^[\t\s]*//)") #exclude // average_merge_method","perim"}
comments = pattern.finditer(line)

for match in comments:
com = match.group(1)

if any(token in line for token in change_list):
found = True
tmp_str = ""
count = 0
while line[count] == "\t":
count += 1
r1 = "});"
if found and r1 in line:
found = False
tmp_str = ""

if found and not line.startswith(com):
tmp_str += line
out += "//" + line

if found and " );" in line:
found = False

tmp_str = tmp_str.replace("\n","")
tmp_str = tmp_str.replace(" ","")
tmp_str = tmp_str.replace("\t","")
tmp_str = "\n" + "\t" * count + tmp_str + "\n"
tmp_str = re.sub('[\t\s]*/\*.*\*/', "", tmp_str) #exclude tolerance line 1683/1715
tmp_str = re.sub("^[\t\s]*\/\*", "\t", tmp_str) #exclude c++ comments
tmp_str = re.sub("\*\/", "", tmp_str) #exclude c++ comments

out += tmp_str
continue

if not found:
out += line
outfile= open("cmos12lpplus.compare.rs_int.rs", "w")
outfile.write(out)