# coding=utf-8
import os
import re
from openpyxl import Workbook
wb = Workbook()
ws = wb.active
pathDir = os.listdir('forcezzz')
for allDir in pathDir:
child = os.path.join('%s%s' % ('forcezzz', allDir))
f = open('E:\myproject\\xixi\\forcezzz\\' + child.replace('forcezzz', ''))
for i in f.readlines():
print i.replace('\n', '')
try:
re_res = re.match('.*com|.*net|.*cn', i.replace('\n', ''), re.M)
print re_res.group() + '====' + i.replace('\n', '').replace(re_res.group(), '').replace(' ', '')
ws.append([re_res.group(), " ", i.replace('\n', '').replace(re_res.group(), '').replace(' ', '')])
except Exception as e:
print 'error', e
wb.save(filename="a.xlsx")
print 'done'
使用python对txt,excel批量操作
最新推荐文章于 2024-09-27 16:08:45 发布