py
def file2list(filepath):
ret = []
with open(filepath, encoding='utf8', mode='r') as f:
ret = [line.rstrip('\n') for line in f.readlines()]
return ret
LB = '\n'
def string2lines(s):
return s.split(LB)
def lines2string(lines):
return LB.join(lines)
def list2file(filepath, ls):
with open(filepath, encoding='utf8', mode='w') as f:
f.writelines(['{:}\n'.format(line) for line in ls] )
def file2str(filepath):
ret = ''
with open(filepath, encoding='utf8', mode='r') as f:
ret = f.read()
return ret
def str2file(filepath, s):
with open(filepath, encoding='utf8', mode='w') as f:
f.write(s)