python 开发IEnglish (三) 文件IO

新建wordio.py

def read_words(words_file):
    with open(words_file, 'r', encoding='utf-8') as fw:
        words = fw.read()
    result = []
    for i in words.split('---'):
        i = i.strip()
        english, chinese = i.split('\n')
        result.append((english, chinese))
    return result

def read_theme(theme_file):
    with open(theme_file, 'r', encoding='utf-8') as ft:
        result = ft.read()
    return result

def write_theme(theme_file, value):
    with open(theme_file, 'w', encoding='utf-8') as ft:
        ft.write(str(value))

词库示例

Great minds have purpose, others have wishes.
杰出的人有着目标,其他人只有愿望。
---
Being single is better than being in an unfaithful relationship.
比起谈着充满欺骗的恋爱,单身反而更好。
---
If you find a path with no obstacles, it probably doesn’t lead anywhere.
太容易的路,可能根本就不能带你去任何地方。
---
Getting out of bed in winter is one of life’s hardest mission.
冬天,将自己从被窝里掏出来,是人生最难的任务之一了。
---
The future is scary but you can’t just run to the past cause it’s familiar.
未来会让人心生畏惧,但是我们却不能因为习惯了过去,就逃回过去。
---
I love it when I catch you looking at me then you smile and look away.
我喜欢这样的时刻:我抓到你正在看我,你笑了,然后害羞地别过脸去。
---
Having a calm smile to face with being disdained indicates kind of confidence.
被轻蔑的时候能平静的一笑,这是一种自信。
---
Success is the ability to go from one failure to another with no loss of enthusiasm.
成功是,你即使跨过一个又一个失敗,但也没有失去热情。
---
Not everything that is faced can be changed, but nothing can be changed until it is faced.
并不是你面对了,任何事情都能改变。但是,如果你不肯面对,那什么也变不了。
---
A guy who whispers in your ears, saying ” It’s alright, I’m here.” Holds you when you’re sad, and treasures everything about you. That’s the guy I want to give my heart to.
那个人会在耳边轻声说:没事,我在这。在你悲伤时给你依靠,与你相关的,他都珍视。有这样的人,我爱定了。

你可能感兴趣的:(python,开发IEnglish,python,python)