day009 作业1 7-26

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)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。