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)
网友评论