| — |
python-files:qss-danci [2011/05/13 07:28] (当前版本) |
||
|---|---|---|---|
| 行 1: | 行 1: | ||
| + | ====== Python读取轻轻松松背单词的GDS词库文件 ====== | ||
| + | 《轻轻松松背单词》是一个广泛使用的背单词软件,有丰富的词库资源。读取轻轻松松背单词GDS词库文件,可以在此基础上开发背单词类软件。 | ||
| + | |||
| + | |||
| + | ===== Python读取GDS词库代码 ===== | ||
| + | |||
| + | <code python> | ||
| + | def set_word_file_path(self,word_file_path): | ||
| + | #读取轻轻松松背单词GDS词库文件 | ||
| + | ''' | ||
| + | gds文件格式 | ||
| + | 第1个单词的英文开始位置 290 +0 长度30 | ||
| + | 第1个单词的中文开始位置 350 +60 长度42 | ||
| + | 第2个单词的英文开始位置 418 +128 | ||
| + | ''' | ||
| + | |||
| + | f = open(word_file_path,'rb') | ||
| + | index = 0 | ||
| + | self.word_file_list = [] | ||
| + | while (index<5000): | ||
| + | f.seek(290+128*index,0) | ||
| + | s1=f.read(30) | ||
| + | if s1=="" or len(s1)<30 : | ||
| + | break | ||
| + | s1 = s1.strip() | ||
| + | f.seek(290+128*index+60,0) | ||
| + | s2=f.read(42).strip() | ||
| + | if s2.find(" ")!= -1 : | ||
| + | s2=s2[:s2.find(" ")] | ||
| + | self.word_file_list.append([s1,s2]) | ||
| + | index = index+1 | ||
| + | f.close() | ||
| + | </code> | ||
| + | |||
| + | ===== 更多 ===== | ||
| + | * 参考:http://www.cnblogs.com/wordanytime/archive/2011/05/09/2041232.html | ||
| + | * GDS词库下载: http://www.pgy.com.cn/bdcxiazaiciku.html | ||