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

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久久亚洲| 亚洲欧洲精品一区| 欧美啪啪一区| 欧美亚洲在线| 久久精品国产亚洲高清剧情介绍 | 亚洲国产一区在线| 欧美激情一区二区| 亚洲一区中文| 久久久久久久国产| 亚洲精品一区在线| 99爱精品视频| 国内精品伊人久久久久av影院| 久久亚洲春色中文字幕| 欧美国产一区二区在线观看| 亚洲深夜福利| 欧美在线播放一区| 99成人精品| 欧美一级黄色网| 亚洲精品社区| 性欧美videos另类喷潮| 亚洲精品日韩久久| 亚洲一区二区三区在线看| 怡红院精品视频| 一区二区三区精品久久久| 狠狠久久亚洲欧美专区| 久久婷婷国产综合精品青草| 亚洲精选久久| 狠狠色丁香婷婷综合影院| 亚洲精品国产拍免费91在线| 国产农村妇女精品一区二区| 亚洲国产美女| 国产综合久久久久久| 亚洲日本成人在线观看| 狠狠色噜噜狠狠狠狠色吗综合| 99国产精品久久久久老师| 精品1区2区| 午夜精品网站| 亚洲在线电影| 欧美精品一区二区三| 美国成人毛片| 国产精品专区第二| 一区二区三区福利| 亚洲人成人一区二区三区| 欧美一区二区三区四区在线观看 | 亚洲欧洲免费视频| 欧美一区1区三区3区公司| 一本色道久久综合亚洲二区三区| 久久精品99久久香蕉国产色戒| 亚洲欧美日韩成人| 欧美日韩在线不卡一区| 亚洲国产成人一区| 亚洲第一色在线| 欧美在线播放一区二区| 欧美在线免费观看| 国产精品久久久久久久久久免费 | 欧美日韩国产天堂| 亚洲第一在线| 亚洲人成在线影院| 久久综合久久88| 女同性一区二区三区人了人一| 国产婷婷色一区二区三区| 亚洲欧美国产视频| 欧美一级播放| 国产亚洲精品久久飘花| 欧美一区二区三区四区在线观看地址| 午夜激情综合网| 国产美女精品视频| 欧美在线精品免播放器视频| 久久久久久尹人网香蕉| 伊人一区二区三区久久精品| 久久久久久久欧美精品| 欧美粗暴jizz性欧美20| 亚洲精品久久| 欧美午夜精品久久久久久超碰| 99热免费精品| 香蕉久久夜色精品国产使用方法| 国产精品揄拍一区二区| 欧美伊人精品成人久久综合97| 久久久精品国产一区二区三区| 精品成人国产| 欧美第一黄网免费网站| 一本大道久久a久久精二百| 欧美一级理论性理论a| 国产啪精品视频| 久久先锋资源| 一本高清dvd不卡在线观看| 午夜日韩在线观看| 激情小说另类小说亚洲欧美| 美女日韩在线中文字幕| 一本综合久久| 久久久久久网址| 日韩视频亚洲视频| 国产欧美亚洲日本| 噜噜噜91成人网| 亚洲素人一区二区| 老司机精品视频一区二区三区| 日韩亚洲国产精品| 国产精品日韩专区| 欧美91精品| 午夜欧美不卡精品aaaaa| 亚洲第一页中文字幕| 午夜伦欧美伦电影理论片| 在线精品国精品国产尤物884a| 欧美精品在线看| 久久精品视频播放| 艳女tv在线观看国产一区| 另类成人小视频在线| 亚洲夜晚福利在线观看| 在线免费观看成人网| 国产精品成人一区二区三区吃奶| 久久久一区二区三区| 亚洲午夜在线观看视频在线| 亚洲国产日韩美| 久久久亚洲高清| 亚洲综合欧美日韩| 亚洲激情网址| 激情欧美一区二区| 国产精品亚洲第一区在线暖暖韩国| 免费成人黄色av| 久久久xxx| 欧美一级成年大片在线观看| 日韩视频一区| 亚洲日本va午夜在线影院| 鲁大师成人一区二区三区| 性做久久久久久久久| 亚洲午夜黄色| 9久re热视频在线精品| 亚洲国产精品一区制服丝袜| 国产一区二区三区的电影 | 在线观看一区欧美| 国产日韩欧美日韩大片| 国产精品久久久久久久一区探花| 欧美精品日韩| 欧美第十八页| 欧美精品xxxxbbbb| 欧美激情第三页| 欧美大片在线观看| 欧美激情欧美狂野欧美精品| 欧美成人精品在线| 欧美gay视频| 欧美电影在线免费观看网站| 麻豆91精品| 欧美二区在线| 欧美精品一区二区三区在线播放 | 亚洲伊人第一页| 亚洲午夜女主播在线直播| 中文日韩在线视频| 亚洲免费中文字幕| 亚洲欧美不卡| 久久国产加勒比精品无码| 欧美中文在线观看国产| 久久精品亚洲一区二区| 久久香蕉国产线看观看av| 老色鬼久久亚洲一区二区| 欧美xxx成人| 欧美日韩一区精品| 欧美无砖砖区免费| 国产美女精品一区二区三区| 国产亚洲成av人片在线观看桃| 激情综合网激情| 亚洲精品在线免费| 亚洲中午字幕| 久久亚洲综合色| 亚洲国产精品一区制服丝袜 | 久久久久久久国产| 欧美成人一品| 亚洲精选国产| 欧美专区在线观看一区| 久久综合伊人| 国产精品jizz在线观看美国| 国产伦精品一区二区三区免费| 国外成人在线| 一区二区三区 在线观看视| 欧美有码视频| 亚洲国产成人一区| 亚洲尤物精选| 欧美国产精品久久| 国产精品一区久久久| 亚洲国产精品福利| 亚洲欧美日韩久久精品| 欧美成人69av| 亚洲一线二线三线久久久| 久久一区二区三区四区五区| 欧美视频在线观看免费| 在线日韩一区二区| 亚洲与欧洲av电影| 欧美成在线视频| 亚洲欧美综合精品久久成人| 欧美国内亚洲| 精久久久久久| 久久国产精品久久久久久久久久| 亚洲片在线资源| 久久久久久午夜| 国产手机视频精品| 中文av字幕一区|