-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestprj.py
More file actions
36 lines (27 loc) · 866 Bytes
/
Copy pathtestprj.py
File metadata and controls
36 lines (27 loc) · 866 Bytes
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
30
31
32
33
34
def getsubstr( str, s, t ):
ist = str.find(s)
ied = str.find(t)
return str[ist+1:ied]
def get_namelink( str ):
name = getsubstr( str, '[', ']' )
link = getsubstr( str, '(', ')' )
return name, link
filepath = 'example.txt'
str1_list = []
str2_list = []
with open(filepath, 'r', encoding='UTF-8') as fp:
line = fp.readline()
while line:
str1,str2 = get_namelink( line )
str1_list.append( str1 )
str2_list.append( str2 )
line = fp.readline()
filename = "output.txt"
with open(filename, 'w', encoding='UTF-8') as fpout:
nLines = len(str1_list)
for i in range( nLines ):
str1 = str1_list[i]
str2 = str2_list[i]
fpout.write("i={}, nLines={}\n".format(i, nLines))
fpout.write("str1={}\n".format(str1))
fpout.write("str2={}\n".format(str2))