Processing text data

# _*_ coding:utf-8 _*_
import re

if __name__ == "__main__":
filename = 'data.txt'
with open(filename,'r',encoding='UTF-8') as file_to_read:
while True:
lines = file_to_read.readline()
sub_lines = lines[6:]
has = sub_lines.find("(")
if has ==-1:
print(sub_lines.strip())
else:
p1 = re.compile(r'(.*?)[(]') # 最小匹配
freezer_kind = re.findall(p1, sub_lines)
print(freezer_kind[0])
if not lines:
break
Baoshan District, Shanghai local literati 
Baoshan District Satan launch point (green Hideki) Shanghai
, Shanghai Baoshan District literati launch point Satan
Baoshan District, Shanghai scholar Fan Deshang

Guess you like

Origin www.cnblogs.com/gylhaut/p/11609187.html