Storing and reading data

# - * - Coding: UTF-. 8 - * - 


from Setting Import *
Import OS
Import SYS

# Print (data_dir)

class DataManage ():
'' 'data storing and reading' ''

DEF the __init __ (Self,):
SYS .path.append (data_dir)

DEF dataWrite (Self, file, value):
'' '
for storing data
: param file: file path
: param value: input content
: return:
' ''
file = the os.path.join ( data_dir, File)
with Open (File, 'W') AS F:
f.write (value)
# Print ( 'data storage directory:% S' File%)

DEF DATAREAD (Self, File):
'' '
Read data
: param file: File Path
: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)




Guess you like

Origin www.cnblogs.com/jinbaobao/p/12028908.html