python将ios及android文件写成excel的小工具,iosandroid,用python将ios及


用python将ios及android文件写成excel的小工具,这个小工具是我在网上看到的。感觉作者写的东西很实用,可能会有人需要用到,就搬来分享给python学习的伙伴们了。
工作时策划抱怨翻译ios的多语言很麻烦,文本文件看起来像这个样子:
/* No comment provided by engineer. */
"下一步" = "下一步";
他想,如果要是像excel这样:
| "下一步" | "下一步" |
两列,则好多了。
于是作者就着手用python语言写了这样一个转换工具。由于我的python初学,所以,写出来的代码还请大家多指点。

python将ios及android文件写成excel的小工具的编程思路是:
静态地址文件读取与转换;动态文件地址读取与转换;这样的反向工程。

还能大家多多指教!

python将ios及android文件写成excel的小工具,源代码:

#!/usr/bin/env python# -*- coding:utf-8 -*-'''# command line tool for reading *.strings file (the file for multi-language supportof ios, the same for android.), make it a excel file for the translator.1. reading file: receive file name and target name2. Created on Jul 18, 2011'''import codecsimport pyExcelerator#采用此方式是为了解决编码问题file = codecs.open("C:/Users/ernest/Desktop/Localizable.strings", 'r', 'utf-8')string = file.read()file.close()#去除无用字段;string = string.replace('/* No comment provided by engineer. */', '').replace('\n', '')#拆分字段;list = [x.split(' = ') for x in string.split(';')]#excel操作;workbook = pyExcelerator.Workbook()ws = workbook.add_sheet('sheet1')#www.iplaypy.comfor x in range(len(list)):    for y in range(len(list[x])):        if list[x][y]:            ws.write(x,y,list[x][y])workbook.save('C:/Users/ernest/Desktop/strings.xls')

编橙之家文章,

评论关闭