An error occurred while loading the file. Please try again.
An error occurred while loading the file. Please try again.
An error occurred while loading the file. Please try again.
-
liguangyu06 authored13859465
import os
from ruamel import yaml
from common.db.db import dbOP
import datetime
curpath = os.path.dirname(os.path.realpath(__file__))
rootPath = os.path.split(curpath)[0]
# 数据读入和写入文件
class FileUtils(object):
def w_info(self, info,keyname):
module=info[2]
dict = {}
value = {}
value['username'] = info[0]
value['goodsname'] = info[1]
key=keyname
dict[key] = value
w_path=rootPath+os.sep+'data'+os.sep+module
# print(w_path)
yamlpath = os.path.join(w_path, "message")
# 写入到yaml文件
with open(yamlpath, "w", encoding="utf-8") as f:
yaml.dump(dict, f, Dumper=yaml.RoundTripDumper,allow_unicode=True)
def r_info(self, module,keyname):
w_path = rootPath + os.sep + 'data' + os.sep + module
yamlpath = os.path.join(w_path, "message")
file_value = open(yamlpath, 'r',encoding='utf-8')
result = yaml.load(file_value.read(), Loader=yaml.Loader)
if result is not None:
key = keyname
if key in result:
return result[key]
else:
return None
else:
return None
if __name__ == '__main__':
# info=("aaaa","bbbbbb","mdm3-pim")
# FileUtils().w_info(info,"产品新增")
aa=FileUtils().r_info("mdm3-pim","产品新增")
print(aa['username'])