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

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>
            久久av资源网| 国产精品久久一区二区三区| 国模私拍一区二区三区| 久久av二区| 久久不射网站| 在线播放中文字幕一区| 欧美国产综合视频| 欧美日本国产在线| 亚洲免费伊人电影在线观看av| 夜夜嗨一区二区| 国产区在线观看成人精品| 久久久久久免费| 欧美不卡高清| 亚洲欧美日韩精品久久| 久久成人国产精品| 亚洲国产精品悠悠久久琪琪| 亚洲国产精品久久久| 欧美性大战久久久久久久蜜臀 | 欧美成人国产一区二区| 一区二区电影免费观看| 亚洲网站视频福利| 有坂深雪在线一区| 一本久道久久久| 樱桃国产成人精品视频| 亚洲精品免费一二三区| 国产日韩欧美精品一区| 亚洲激情视频在线观看| 国产精品美女视频网站| 欧美大片一区二区| 国产精品va在线播放| 久久久亚洲影院你懂的| 欧美日韩国产免费观看| 久久久久中文| 欧美日韩亚洲国产精品| 玖玖精品视频| 国产精品婷婷午夜在线观看| 亚洲盗摄视频| 国内精品久久久久影院优| 99re这里只有精品6| 精品盗摄一区二区三区| 中日韩美女免费视频网站在线观看 | 欧美国产丝袜视频| 国产精品一区二区久久| 最新高清无码专区| 黄色成人在线免费| 亚洲欧美综合精品久久成人| 日韩图片一区| 美玉足脚交一区二区三区图片| 欧美一二三视频| 欧美日韩亚洲天堂| 亚洲欧洲综合另类| 亚洲国内自拍| 久久久久久久久久久久久女国产乱| 亚洲视频你懂的| 欧美日本韩国| 亚洲国产一区视频| 亚洲精品国产日韩| 欧美18av| 亚洲国产导航| 亚洲激情午夜| 欧美激情bt| 91久久极品少妇xxxxⅹ软件| 在线欧美亚洲| 久久尤物视频| 亚洲二区三区四区| 亚洲激情婷婷| 欧美激情亚洲| 亚洲精品国精品久久99热| 日韩亚洲欧美成人| 欧美日韩精品免费观看视频完整| 欧美激情乱人伦| av成人免费| 国产精品vip| 亚洲欧美国产毛片在线| 欧美制服丝袜| 精品99视频| 猛干欧美女孩| 日韩亚洲精品电影| 亚洲欧美日韩国产综合精品二区| 国产精品一区二区久久久久| 亚洲免费网站| 麻豆成人在线观看| 亚洲黄网站在线观看| 欧美日本国产在线| 亚洲一区二区三区精品在线| 欧美在现视频| 亚洲人体偷拍| 国产精品免费福利| 久久免费的精品国产v∧| 亚洲激情成人在线| 亚洲欧美日韩成人| 伊人精品久久久久7777| 欧美日韩成人在线视频| 亚洲小视频在线观看| 久久久噜噜噜| 一区二区三区产品免费精品久久75| 国产精品久久7| 老司机免费视频一区二区| 亚洲人体一区| 久久久久久欧美| 这里只有精品视频| 国内精品久久久久影院 日本资源 国内精品久久久久伊人av | 亚洲第一精品久久忘忧草社区| 欧美成人免费小视频| 亚洲一区免费| 欧美激情久久久| 欧美一区中文字幕| 99re国产精品| 在线免费不卡视频| 国产精品裸体一区二区三区| 久久影视精品| 欧美在线免费看| 一本到高清视频免费精品| 麻豆精品视频在线| 欧美一区二区免费观在线| 亚洲精品国产精品国自产观看| 国产精品久久久久久久久久久久久久| 久久久久久久一区二区三区| 亚洲一区二区三区777| 欧美激情网友自拍| 久久久噜噜噜久久狠狠50岁| 亚洲欧美日韩一区二区| 日韩视频在线永久播放| 亚洲成人在线视频网站| 国产日韩亚洲欧美精品| 欧美三级精品| 欧美日韩国产首页| 免费在线日韩av| 久久九九精品| 欧美在线视频免费| 羞羞答答国产精品www一本| 亚洲视频 欧洲视频| 亚洲欧洲精品一区二区三区不卡 | 欧美高清视频免费观看| 久久精品国产99国产精品| 亚洲尤物在线视频观看| 夜夜夜精品看看| 亚洲精品永久免费精品| 亚洲精品女av网站| 亚洲国产精品成人综合色在线婷婷| 国产色综合网| 国产日韩精品一区观看| 国产三区精品| 狠狠干综合网| 黑人中文字幕一区二区三区| 国产婷婷色一区二区三区| 国产区在线观看成人精品| 国产精品日韩| 国产亚洲精品7777| 国产一区91| 尤物精品在线| 91久久午夜| 99riav久久精品riav| 一区二区三区四区国产精品| 亚洲最新在线视频| 亚洲综合日韩中文字幕v在线| 亚洲欧美日韩在线一区| 午夜欧美不卡精品aaaaa| 欧美专区亚洲专区| 美国三级日本三级久久99| 欧美成人亚洲成人| 亚洲人成亚洲人成在线观看| 日韩一区二区精品视频| 亚洲尤物在线视频观看| 久久精品导航| 欧美日韩国产不卡在线看| 国产精品久久久久高潮| 狠狠狠色丁香婷婷综合久久五月| 亚洲高清网站| 一区二区三区精品视频在线观看| 亚洲欧美中文日韩v在线观看| 久久精品水蜜桃av综合天堂| 欧美成人tv| 亚洲性夜色噜噜噜7777| 久久精品免费观看| 欧美女人交a| 国产日本欧美一区二区| 亚洲精品在线观看免费| 午夜综合激情| 亚洲电影有码| 午夜日本精品| 欧美精品成人91久久久久久久| 国产精品日产欧美久久久久| 亚洲国产欧美另类丝袜| 先锋资源久久| 亚洲人屁股眼子交8| 久久精品国产精品亚洲综合| 欧美日韩一区二区三区免费看 | 欧美va亚洲va日韩∨a综合色| 国产精品久久久久久久久动漫| 一区在线视频| 亚洲欧美一区二区视频| 亚洲高清视频中文字幕| 香蕉成人伊视频在线观看| 欧美激情视频一区二区三区免费 | 久久久久久久国产| 一区二区三区日韩欧美精品| 免费观看久久久4p| 国产亚洲一本大道中文在线| 亚洲尤物视频在线|