import json
def read_file(path):
"""
Read a file.
:param path:
:return:
"""
with open(path, 'r', encoding='utf-8') as f:
f.read()
def rewrite_file(path, content):
"""
Cover the origin file with content that commit .
:param path: where file locate at
:param content:content that will write into file
:return:
"""
with open(path, 'w', encoding='utf-8') as f:
f.write(content)
def write_file(path, content):
"""
Insert content after the origin file .
:param path: where file locate at
:param content: content that will write into file
:return:
"""
with open(path, 'a', encoding='utf-8') as f:
f.write(content)
def read_binary_file(path):
"""
Read a binary file.
:param path:
:return:
"""
with open(path, 'rb', encoding='utf-8') as f:
f.read()
def rewrite_binary_file(path, content):
"""
Cover the origin binary file with content that commit .
:param path: where file locate at
:param content:content that will write into file
:return:
"""
with open(path, 'wb', encoding='utf-8') as f:
f.write(content)
def read_json_file(path):
"""
Read a .json file.
:param path:
:return:
"""
with open(path, 'r', encoding='utf-8') as f:
json.load(f)
def write_json_file(path, content):
"""
Cover the .json file with content.
:param path:
:param content:
:return:
"""
with open(path, 'w', encoding='utf-8') as f:
json.dump(content, f)
def convert_json_to_python(content):
json.loads(content, encoding='utf-8')
def convert_python_to_json(content):
json.dumps(content)
day009 作业1 7-26
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...