python ios string转excel
#!/usr/bin/python#!/usr/bin/env python# -*- coding:utf-8 -*-from tempfile import TemporaryFilefrom xlwt import Workbookimport re,sys,os dir = sys.path[0]print dir book = Workbook(encoding='...
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from tempfile import TemporaryFile
from xlwt import Workbook
import re,sys,os
dir = sys.path[0]
print dir
book = Workbook(encoding='utf-8')
pattern = re.compile(r'".+?"')
pattern3 = re.compile(r'')
for file in os.listdir(dir):
fileName = os.path.splitext(file)[0]
print "filename",fileName
fileExt = os.path.splitext(file)[1]
print "fileExt",fileExt
if os.path.isfile(file) and fileExt == '.strings':
# print 'processing file: ', file
sheet = book.add_sheet(fileName)
f = open(file, "r")
print("filename",fileName)
if fileName == 'InfoPlist':
row_index = 0
for line in f:
match = re.match(r'\w+=', line)
if match:
sheet.write(row_index,0,match.group()[:-1])
match2 = pattern.search(line)
if match2:
sheet.write(row_index,1,match2.group()[1:-1])
row_index = row_index + 1
else:
row_index = 0
for line in f:
# if line.startswith(''):
# print("start")
col_index = 0
print "line --","\""+line
line = "\""+line
a = line.replace('=','"=')
# print "a --",a
for m in pattern.finditer(a):
# print "m --",m
sheet.write(row_index,col_index,m.group()[1:-1].rstrip())
# print "row_index",row_index
# print "col_index",col_index
# print "key",m.group()[1:-1]
col_index = col_index + 1
row_index = row_index + 1
pass
f.close()
book.save('string/text.xls')
book.save(TemporaryFile())
string数据如下
name ="zhangsan";
age ="30";
更多推荐
所有评论(0)