with open(inFileName) as file1, open(outFileName,'w') as file2:
file_line= file1.read().splitlines()
for one in file_line:
if one.count(';') != 1:
continue
name,pwd= one.split(';')
file2.write(name+ '\n')
实战
with open('./log.csv', encoding='gbk') as rf, open('./token','a+') as wf:
reader = csv.reader(rf)
for val in reader:
token = re.findall('token":"(.*?)"}', val[0])[0]
wf.write(token+'\n')
with open('./log.csv', encoding='gbk') as rf, open('./token','a+', newline='') as wf:
reader = csv.reader(rf)
writer = csv.writer(wf)
for val in reader:
token = re.findall('token":"(.*?)"}', val[0])
writer.writerow(token)