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

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>
            欧美大尺度在线观看| 亚洲激情在线观看视频免费| 国产欧美另类| 亚洲综合视频一区| 久久频这里精品99香蕉| 永久域名在线精品| 欧美精品18+| 亚洲图片在区色| 久久躁日日躁aaaaxxxx| 亚洲精品乱码久久久久久日本蜜臀 | 一本久久青青| 国产精品久久久一区二区三区| 午夜日韩电影| 欧美激情亚洲| 亚洲男人第一网站| 伊人久久av导航| 欧美揉bbbbb揉bbbbb| 欧美一级视频| 亚洲精品中文字幕女同| 欧美一区二区三区免费观看| 亚洲大片精品永久免费| 欧美午夜激情小视频| 久久精品一本| 99re6这里只有精品视频在线观看| 欧美一区二区在线| 亚洲精品中文字幕有码专区| 国产日韩精品一区观看| 免播放器亚洲| 亚洲欧美日韩精品久久奇米色影视 | 麻豆国产精品va在线观看不卡| 亚洲另类春色国产| 久久亚洲综合网| 亚洲女同精品视频| 91久久国产综合久久| 国产欧美日韩视频在线观看| 欧美成人午夜免费视在线看片| 亚洲综合精品自拍| 亚洲精品欧美日韩专区| 久久伊人免费视频| 性做久久久久久| 中文日韩欧美| 最新国产成人av网站网址麻豆| 国产精品午夜电影| 欧美色精品天天在线观看视频| 久久香蕉国产线看观看av| 亚洲欧美国产三级| 一本色道久久综合狠狠躁篇怎么玩| 男人的天堂成人在线| 久久精品99| 午夜精品福利一区二区三区av| 日韩特黄影片| 亚洲精品国产精品乱码不99| 一区二区三区在线免费观看| 国产日韩视频一区二区三区| 国产精品s色| 欧美日韩一区三区四区| 欧美激情第9页| 欧美国产专区| 欧美国产1区2区| 农村妇女精品| 欧美福利网址| 欧美国产第一页| 欧美成人dvd在线视频| 久久最新视频| 美女露胸一区二区三区| 美女精品在线| 欧美肥婆在线| 欧美日韩亚洲一区二| 欧美乱妇高清无乱码| 欧美女激情福利| 欧美日韩99| 欧美日韩一区三区| 国产精品高潮呻吟视频| 国产精品青草综合久久久久99 | 国产欧美一区二区精品婷婷| 国产精品三级视频| 国产欧美一区二区精品秋霞影院 | 欧美91视频| 欧美国产激情二区三区| 欧美激情一区二区三区不卡| 欧美国产视频在线观看| 欧美全黄视频| 欧美性做爰毛片| 国产欧美1区2区3区| 国产日韩欧美综合| 尤物yw午夜国产精品视频明星| 伊人久久综合| 亚洲精品免费一二三区| 一区二区免费在线视频| 亚洲欧美视频在线观看视频| 欧美中文字幕第一页| 久久综合电影| 91久久久久久| 亚洲综合大片69999| 久久er精品视频| 免费亚洲电影在线| 国产精品v欧美精品v日韩精品| 国产精品美女999| 激情成人av| 在线亚洲欧美| 久久久五月天| 亚洲精品日韩一| 午夜精品一区二区三区四区| 久久免费精品日本久久中文字幕| 欧美成人精品一区二区| 国产精品www| 尤物yw午夜国产精品视频明星| 99精品国产在热久久下载| 欧美一级网站| 欧美激情亚洲另类| 亚洲男人的天堂在线| 久久亚洲色图| 国产精品嫩草影院av蜜臀| 亚洲第一精品电影| 欧美亚洲三级| 亚洲欧洲精品一区| 欧美在线一级视频| 欧美体内she精视频| 亚洲二区视频在线| 香蕉国产精品偷在线观看不卡| 欧美国产在线观看| 欧美一级大片在线免费观看| 欧美精品123区| 在线成人www免费观看视频| 亚洲午夜精品久久久久久浪潮| 美女视频网站黄色亚洲| 中文有码久久| 欧美裸体一区二区三区| 在线观看亚洲一区| 欧美一区二区私人影院日本| 亚洲精选91| 女同性一区二区三区人了人一 | 亚洲福利视频专区| 久久国产精品色婷婷| 日韩视频在线一区二区| 久久久久久久久久久一区| 国产精品一区二区三区观看| 99热免费精品在线观看| 欧美电影在线观看| 久久成人国产精品| 国产精品资源在线观看| 亚洲一区二区免费在线| 亚洲欧洲日韩女同| 麻豆成人在线播放| 尤物九九久久国产精品的特点 | 一区二区三区精品在线| 欧美成人免费在线观看| 久久精品久久99精品久久| 国产精品亚洲综合色区韩国| 亚洲线精品一区二区三区八戒| 亚洲高清久久| 免费不卡中文字幕视频| 亚洲成人在线网| 久久久久se| 久久国产精品色婷婷| 国产字幕视频一区二区| 久久精品国产久精国产爱| 亚洲欧美第一页| 国产欧美日韩专区发布| 欧美在线免费播放| 欧美一区免费| 国产亚洲欧美另类中文 | 亚洲一区亚洲| 国产精品视频yy9099| 欧美一区成人| 午夜精品婷婷| 国产主播在线一区| 狂野欧美激情性xxxx| 久久嫩草精品久久久精品一| 1024亚洲| 91久久久久久久久久久久久| 欧美喷水视频| 亚洲欧美日本国产有色| 午夜精品短视频| 精品成人乱色一区二区| 欧美国产成人精品| 欧美日韩精品一区二区三区| 亚洲天堂av在线免费| 亚洲视频一二区| 国产香蕉97碰碰久久人人| 久久亚洲精品伦理| 男人的天堂亚洲| 亚洲视频国产视频| 午夜亚洲激情| 亚洲国产日韩欧美在线99| 亚洲另类春色国产| 国产欧美一区二区在线观看| 久久午夜精品一区二区| 欧美大片91| 午夜精品久久久久久久久久久久| 欧美一区二区三区免费观看视频| 一区二区三区在线高清| 亚洲精品日韩在线| 国产日产精品一区二区三区四区的观看方式 | 日韩视频免费观看高清完整版| 国产精品免费网站在线观看| 老司机精品久久| 欧美日韩国产综合在线| 久久精品国产视频| 欧美高清视频在线|