-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
29 lines (22 loc) · 946 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
def modify_line_find(filename, find_str):
all_line = ""
with open(filename, "r+", encoding='utf-8') as file_handle:
all_line = file_handle.readlines()
for idx, ll in enumerate(all_line):
find_index = ll.find(find_str)
if ll.find(find_str) != -1:
this_line = all_line[idx]
print('this_line', this_line)
prefix = this_line[:find_index]
print("prefix", prefix)
suffix = this_line[find_index+len(find_str):]
print("suffix", suffix)
all_line[idx] = prefix+'[////]'+suffix
with open('.output', "w+", encoding='utf-8') as file_handle:
file_handle.writelines(all_line)
project_path = os.path.realpath(os.path.dirname(__file__))
print("project_path:", project_path)
filename = f'{project_path}/temp'
# if __name__ == '__main__':
# modify_line_find("temp", '04')