青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 319, comments - 22, trackbacks - 0, articles - 11
  C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

Parse .strings file with Python

Posted on 2013-01-08 13:44 RTY 閱讀(604) 評論(0)  編輯 收藏 引用 所屬分類: Mac os轉載隨筆

Parse .strings file with Python

I'm trying to write a small Python script to parse the .strings file in my iPhone application project and determine which keys might not be in use. I'm, also doing some string matching to filter out some of the results. This is where my problems start :). If I try something like

for file_line in strings_file: if 'search_keyword' in file_line: ...

the search keyword will often not match, even though if I print every file line in the same for I seem to be reading the text correctly and my search keywords appear.

The problem is these .strings files are in some binary format. Does anyone know of a proper way to parse these files?

asked Jan 25 '10 at 12:49
Mihai Damian
2,51631736

80% accept rate
Can you post an example .strings file? – Tim Pietzcker Jan 25 '10 at 12:57
They are pretty standard in format. I have lines like: "Keyword" = "Value"; or "Keyword" = 0.0; The files are correct as far as they're concerned. I use them from Objective-C and I have no problems there. It's just that there I use some framework provided class to open them which I probably can't use from Python – Mihai Damian Jan 25 '10 at 13:04
So how do you open the file? What does printing the repr() of a line you think should match show you? – Thomas Wouters Jan 25 '10 at 13:05
1 
I open it with open(filename, 'r'). Also tried 'U'. 'b' is not supported on Mac OS – Mihai Damian Jan 25 '10 at 13:11
It just occurred to me I might be able to use PyObjC to use the Objective-C code that reads these files. I'm still open to simpler solutions though – Mihai Damian Jan 25 '10 at 13:14
show 1 more comment
feedback

Use correct encoding to open the .strings-file and in your source code. According to documentationthe encoding of your file could be utf-16.

# -*- coding: utf-8 -*- import codecs  for line in codecs.open(u'your_file.strings', encoding='utf-16'): if u'keyword' in line: # process line
answered Jan 25 '10 at 13:27
J.F. Sebastian
61.9k1096173
Thanks, this works perfectly. Using your solution I realized some of my .strings were encoded utf-8 and most were utf-16. This probably explains why the matching worked only in some of the files. – Mihai Damian Jan 25 '10 at 13:55
feedback

No experience with those .strings files, but here is the reason why you don't find matches:

strings_file.read()

returns a string with the full content of the file. Iterating over a string iterates over single characters, i.e. in your for loop, file_line isn't a line, it's always just one single character (a string of length 1), which obviously can't contain a multi-character search word.

answered Jan 25 '10 at 12:57
balpha
12.9k55177
Indeed. Use for line in strings_file: instead. – Thomas Wouters Jan 25 '10 at 13:01
Ah, you are right, I was using simply for file_line in strings_file:, without the read(); will edit in a moment – Mihai Damian Jan 25 '10 at 13:02
@MihaiD: for line in file will only work (as expected) on plain text files, which (as you say) the.strings files are not. – balpha Jan 25 '10 at 13:05
feedback

It sounds like the stings file was saved as data. If python can't read it as is you can convert it to a plain text file in Objective-c.

Just: (1) read the strings file into a file with the proper encoding. (2) Convert to dictionary (3) write dictionary to another file.

So:

NSString *strings=[NSString stringWithContentsOfFile:filePath encoding:NSUTF16StringEncoding error:&error]; NSDictionary *dict=[strings propertyList]; [dict writeToFile:anotherFilePath atomically:NO]; 
answered Jan 25 '10 at 13:33
TechZen
42.3k74379
Yes, that's one way to go. Will keep in mind if all else fails. – Mihai Damian Jan 25 '10 at 13:47
feedback

Your Answer

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美国产综合| 老司机免费视频一区二区| 久久久青草青青国产亚洲免观| 亚洲欧洲一区二区三区| 老牛影视一区二区三区| 永久91嫩草亚洲精品人人| 久久久亚洲欧洲日产国码αv| 亚洲免费影视| 黄色国产精品| 亚洲电影在线观看| 欧美日韩中文在线| 欧美一级欧美一级在线播放| 亚洲免费观看高清完整版在线观看熊| 欧美日韩国产精品自在自线| 亚洲人成网站色ww在线| 最新日韩在线视频| 欧美三级电影大全| 久久免费视频这里只有精品| 午夜国产精品影院在线观看| 国产欧美日韩综合一区在线播放| 久久成人精品一区二区三区| 亚洲欧美日韩在线一区| 狠狠爱www人成狠狠爱综合网 | 久久久视频精品| 亚洲国产精品日韩| 一个色综合导航| 激情综合中文娱乐网| 亚洲黄色成人网| 国产美女精品视频| 亚洲国产日韩一级| 国产精品一区二区在线| 猫咪成人在线观看| 国产精品久久久久久久浪潮网站 | 国产一区二区三区视频在线观看 | 久久综合成人精品亚洲另类欧美| 久久免费国产精品| 亚洲欧洲99久久| 欧美国产视频一区二区| 欧美亚洲免费电影| 欧美伦理一区二区| 久久一区精品| 国产精品永久入口久久久| 欧美激情亚洲自拍| 国产欧美日韩精品一区| 亚洲国产精品va在线观看黑人| 欧美午夜a级限制福利片| 久久天天躁夜夜躁狠狠躁2022| 欧美精品在线视频| 欧美成人午夜77777| 国产精品亚洲人在线观看| 亚洲高清资源综合久久精品| 欧美三级第一页| 亚洲黄色成人久久久| 国产一区二区三区日韩欧美| 亚洲国产欧美在线人成| 国内精品久久久久久久影视蜜臀| 亚洲精品专区| 日韩小视频在线观看| 久久久久成人网| 久久天天躁狠狠躁夜夜av| 国产精品mv在线观看| 亚洲国产欧美在线人成| 国产亚洲欧洲| 亚洲欧美色婷婷| 欧美一区二区三区免费视频| 欧美大片免费观看在线观看网站推荐| 欧美一区成人| 国产日韩亚洲欧美| 欧美在线影院| 久久亚洲视频| 亚洲国产精品一区二区第四页av| 午夜久久99| 久久久久9999亚洲精品| 国产视频一区二区在线观看| 日韩写真视频在线观看| 夜夜爽av福利精品导航 | 麻豆久久精品| 亚洲第一精品电影| 99人久久精品视频最新地址| 久久精彩免费视频| 欧美jizz19hd性欧美| 激情欧美一区| 麻豆成人av| 亚洲日本激情| 午夜一区不卡| 狠狠色噜噜狠狠狠狠色吗综合| 欧美在线免费观看| 欧美高清不卡| 亚洲午夜未删减在线观看| 欧美私人网站| 久久电影一区| 亚洲国产一区二区三区a毛片| 亚洲精品乱码久久久久久黑人| 欧美国产综合一区二区| 亚洲狼人综合| 久久精品亚洲乱码伦伦中文| 国产欧美精品日韩精品| 久久福利一区| 99国产精品久久久久久久成人热| 亚洲一区二区在线看| 国产欧美日韩精品丝袜高跟鞋 | 欧美大片一区二区三区| 日韩视频精品在线| 国产欧美一区二区色老头| 久久久国产午夜精品| 亚洲激情第一区| 欧美在线观看天堂一区二区三区| 国产精品户外野外| 狼狼综合久久久久综合网| 亚洲人成7777| 久久只精品国产| 亚洲欧美影音先锋| 亚洲人成7777| 国产在线不卡视频| 国产精品海角社区在线观看| 亚洲欧美日韩高清| 欧美日韩国产美女| 久久久久九九视频| 亚洲一区二区三区四区在线观看 | 亚洲美女视频在线免费观看| 亚洲欧美国产精品专区久久| 国产精品嫩草久久久久| 美女视频黄 久久| 欧美在现视频| 午夜精彩国产免费不卡不顿大片| 亚洲第一精品夜夜躁人人躁| 亚洲一区二区三区涩| 91久久精品国产91性色tv| 国产欧美亚洲日本| 国产精品久久久久一区二区三区共| 久久久91精品国产| 午夜精品视频网站| 亚洲视频欧洲视频| 夜夜嗨av一区二区三区网页| 久久久久久久久久久久久久一区| 99视频在线观看一区三区| 精品va天堂亚洲国产| 国产精品视频一区二区高潮| 麻豆精品视频| 老司机一区二区| 麻豆成人小视频| 麻豆精品网站| 欧美韩日一区二区| 男女精品网站| 欧美激情一区二区三区不卡| 午夜久久99| 久久精品国产在热久久| 午夜精品一区二区三区在线播放| 一区二区三区高清在线| 亚洲精品乱码视频 | 亚洲欧美激情在线视频| 亚洲最快最全在线视频| 亚洲精品视频一区| 一区二区三区日韩精品| 日韩亚洲一区在线播放| 亚洲美女毛片| 亚洲午夜精品视频| 香蕉久久国产| 老司机午夜精品| 亚洲第一在线综合在线| 欧美激情视频在线免费观看 欧美视频免费一 | 亚洲精品欧美精品| 亚洲乱码一区二区| 亚洲一区日韩在线| 久久黄金**| 欧美成人首页| 99精品国产在热久久| 一区二区三区欧美激情| 亚洲一区在线看| 久久精品欧洲| 欧美日韩日本视频| 国产日韩精品久久久| 国产一区激情| 99re热这里只有精品视频| 一区二区冒白浆视频| 亚洲综合日韩| 欧美成人午夜激情视频| 欧美激情中文不卡| 亚洲影院免费| 欧美成人免费一级人片100| 欧美久色视频| 国产日韩一级二级三级| 亚洲大片在线| 欧美一区成人| 亚洲区中文字幕| 欧美一区网站| 欧美日韩一区不卡| 国产亚洲欧洲| 亚洲一区欧美激情| 欧美成人性网| 亚洲欧美一区二区激情| 久久午夜精品一区二区| 欧美午夜视频网站| 亚洲国内精品| 久久米奇亚洲| 亚洲嫩草精品久久| 欧美日韩色婷婷| 亚洲日韩中文字幕在线播放| 一区二区三区视频在线看| 久久久久成人精品免费播放动漫|