#读取文件
import os
# import json
# import pickle
def read_file(file):
path1 = os.path.abspath('0310')
# print(path1)
# get_file_list = os.listdir(path1)
# print(get_file_list, type(get_file_list)) #打印文件列表
path_file = path1 + '\\' + file
# print(path_file)
with open(path_file, 'r', encoding='utf8') as f:
# res=json.dumps(f)
data = f.read()
print(data)
def menu():
print("""
1、 1.txt
2、 2.txt
3、 3.txt
4、 4.txt
请输入你要读取的文件""")
func_dict = {
'1' :read_file,
'2' :read_file,
'3' :read_file,
'4' :read_file,
}
def run():
menu()
global func_dict
while True:
cmd=input().strip()
if cmd in func_dict:
res=func_dict[cmd]
return res(cmd+'.txt')
else:
print('重输')
run()
image.png
网友评论