データの格納と読み込み

1325 ワード

# -*- coding:utf-8 -*-


from setting import *
import os
import sys

# print(DATA_DIR)

class DataManage():
''' '''

def __init__(self,):
sys.path.append(DATA_DIR)

def dataWrite(self, file, value):
'''

:param file:
:param value:
:return:
'''
file = os.path.join(DATA_DIR, file)
with open(file, 'w') as f:
f.write(value)
# print(' :%s'%file)

def dataRead(self, file):
'''

:param file:
:return: list
'''
try:
file = os.path.join(DATA_DIR, file)
with open(file, 'r') as f:
data = f.readlines()
return data
except FileNotFoundError as e:
print(e)

if __name__ == '__main__':
file = 'doorTicket\orange.datas'
data = DataManage()
data.dataWrite(file=file, value='world')
res = data.dataRead(file)
print(res)