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

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久久线看在观草草青青| 久久欧美中文字幕| 亚洲国产欧美日韩另类综合| 暖暖成人免费视频| 欧美高清免费| 亚洲在线1234| 午夜视频在线观看一区二区三区| 国产日韩在线亚洲字幕中文| 欧美在线免费观看亚洲| 久久www成人_看片免费不卡| 伊人夜夜躁av伊人久久| 男人的天堂亚洲在线| 欧美第一黄色网| 香蕉成人久久| 欧美尤物一区| 一区二区高清在线| 欧美一二三视频| 91久久国产精品91久久性色| 妖精视频成人观看www| 国产日韩精品在线播放| 欧美aⅴ一区二区三区视频| 欧美日本国产视频| 亚洲欧美日韩在线观看a三区| 性欧美8khd高清极品| 亚洲麻豆一区| 欧美一区二区三区在线观看| 亚洲国产精品va在线观看黑人| 日韩一二在线观看| 永久久久久久| 亚洲欧美韩国| av成人免费| 久久青草福利网站| 先锋影音国产一区| 欧美大片在线看| 久久婷婷激情| 国产精品久久久久久久app| 久久人人爽人人爽爽久久| 欧美色另类天堂2015| 麻豆久久精品| 国产日产欧美精品| 日韩性生活视频| 亚洲韩国日本中文字幕| 性色av一区二区三区红粉影视| 亚洲精品综合| 久久综合综合久久综合| 久久国产精品久久久| 欧美性生交xxxxx久久久| 欧美高清视频| 亚洲国产欧美日韩精品| 欧美中文在线免费| 欧美一区二区视频在线观看2020| 欧美日韩中文字幕日韩欧美| 最新69国产成人精品视频免费| 国内一区二区在线视频观看 | 久久成人精品| 国产精品精品视频| 一区二区三区视频在线看| 99热这里只有精品8| 免费观看在线综合| 欧美成人dvd在线视频| 在线观看的日韩av| 久久香蕉国产线看观看av| 久久婷婷国产综合精品青草| 国产一区二区黄| 西西裸体人体做爰大胆久久久| 销魂美女一区二区三区视频在线| 国产精品国内视频| 亚洲欧美国产视频| 久久国产精品久久久久久久久久 | 国产视频自拍一区| 先锋影音一区二区三区| 久久精品国产亚洲高清剧情介绍| 国产精品欧美日韩一区| 亚洲综合日韩在线| 久久久久9999亚洲精品| 在线观看中文字幕不卡| 乱人伦精品视频在线观看| 亚洲电影免费| 99精品视频免费观看视频| 欧美日韩在线精品| 亚洲男女毛片无遮挡| 久久久精品性| 亚洲破处大片| 欧美日韩日本视频| 欧美亚洲在线| 欧美好吊妞视频| 亚洲视频在线视频| 国产精品资源在线观看| 久久女同精品一区二区| 亚洲精品一级| 欧美在线看片a免费观看| 伊人久久亚洲热| 欧美日韩亚洲一区二区| 亚洲欧美成人一区二区在线电影| 久久精品国产91精品亚洲| 136国产福利精品导航网址| 欧美激情一区二区在线| 亚洲欧美一区二区三区在线 | 亚洲视频在线观看免费| 国产一区二区精品丝袜| 欧美大片一区| 欧美一区二区三区的| 亚洲第一视频网站| 欧美在线啊v| 99视频国产精品免费观看| 国产日韩在线看片| 欧美久久久久| 久久手机精品视频| 亚洲一区免费视频| 亚洲国产精品久久久久久女王| 欧美一区二区视频网站| 99视频精品在线| 伊人久久男人天堂| 国产日产高清欧美一区二区三区| 欧美激情1区2区| 久久久精品999| 亚洲午夜激情免费视频| 亚洲国产精品久久久久久女王| 久久精品一区二区三区四区| 一级成人国产| 亚洲免费成人| 亚洲人久久久| 亚洲国产精品成人一区二区| 国产视频精品免费播放| 欧美系列电影免费观看| 免费影视亚洲| 久久久一区二区三区| 香蕉久久夜色精品| 亚洲影院色无极综合| 日韩午夜电影| 亚洲精选久久| 亚洲激情黄色| 亚洲成人直播| 免费av成人在线| 久久久之久亚州精品露出| 欧美一区2区三区4区公司二百 | 国产麻豆精品theporn| 欧美日韩一区不卡| 欧美日韩喷水| 欧美日韩一区二区在线播放| 欧美激情一区二区三区不卡| 欧美成ee人免费视频| 女人天堂亚洲aⅴ在线观看| 另类欧美日韩国产在线| 久久综合一区| 欧美成人有码| 欧美高清在线视频| 老司机一区二区| 欧美成人免费在线观看| 欧美国产在线视频| 欧美日本精品在线| 国产精品看片资源| 国产日韩精品在线播放| 国内精品美女在线观看| 1769国内精品视频在线播放| 亚洲福利视频二区| 亚洲六月丁香色婷婷综合久久| 99这里有精品| 亚洲欧美在线另类| 久久久久久亚洲综合影院红桃| 蜜臀av在线播放一区二区三区| 欧美ab在线视频| 亚洲国产精品久久精品怡红院| 亚洲精品在线免费| 亚洲视频综合| 久久午夜精品| 欧美午夜精品伦理| 韩国一区二区三区在线观看| 亚洲成色精品| 亚洲欧美日韩国产成人| 久久精品日韩欧美| 亚洲国产日韩欧美综合久久| 亚洲一区二区毛片| 久久久国际精品| 欧美三区在线观看| 永久免费毛片在线播放不卡| 99re热精品| 久久久女女女女999久久| 亚洲国产精品99久久久久久久久| 亚洲美女在线观看| 久久久久久亚洲综合影院红桃| 欧美福利网址| 国产综合自拍| 亚洲曰本av电影| 亚洲大胆美女视频| 午夜激情亚洲| 欧美日韩国产小视频在线观看| 国产午夜精品视频| 一区二区三区免费看| 葵司免费一区二区三区四区五区| 亚洲美女一区| 欧美成人精品一区二区三区| 国产精品视频yy9099| 亚洲国产精品专区久久|