《轻轻松松背单词》是一个广泛使用的背单词软件,有丰富的词库资源。读取轻轻松松背单词GDS词库文件,可以在此基础上开发背单词类软件。

    #---------------------------------------------
    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()
        
    #---------------------------------------------

posted on 2011-05-09 15:51  WordAnyTime  阅读(1567)  评论(0编辑  收藏  举报