用Python给宝宝写一个故事机
运行环境及其说明
-
Windows
-
Python3.6以上
-
可以朗读中文
需要安装的库
+ pypiwin32(用于朗读)
pip install pypiwin32
+ pandas(用于记录上一次阅读位置)
pip install pandas
+ linecache(读取文本文件的指定行)
pip install linecache
程序如下
"""
Create on Jan-30-2020
Author:CC
Evn:Python3.6
Only test on windows10
"""
import os, pandas as pd, linecache as lch, win32com.client
class cachefile:
"""
Read specific line of a txt
"""
def __init__(self, file_path):
self.max_line = len(lch.getlines(file_path))
self.file_path = file_pathdef getline(self, num):
if 0 <= num &