import os
import json
import configparser
from configgg.conf import DATA_PATH
读取text/csv文件代码
@staticmethod
def get_data_text(filename):
# 同样适用于csv
data = []
try:
if os.path.exists(filename):
file = open(filename, "r", encoding="utf_8")
for line in file:
d1 = line.strip().split(",")
data.apend(d1)
except Exception as e:
print(e)
return data
csv文件
name,age,adress
小明,10,上海
小黄,11,北京
小苗,13,江苏
读取json文件代码
@staticmethod
def get_data_json(filename):
if os.path.exists(filename):
file=open(filename,"r",encoding="utf-8")
result=json.load(file.read())
return result