美文网首页
day009 作业1 7-26

day009 作业1 7-26

作者: Yehao_ | 来源:发表于2018-07-26 20:08 被阅读0次
    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

          本文链接:https://www.haomeiwen.com/subject/rbkimftx.html