美文网首页
文件操作作业

文件操作作业

作者: 蘑菇plus | 来源:发表于2018-07-26 23:01 被阅读0次

    封装文件的读写操作,写操作,写入需要写入文件的内容和地址;读操作,写入需要读取的文件地址。
    HomeWork.py

    
    import json
    def my_read(address):
        with open('address','encoding=utf-8') as ff:
            gg=ff.read()
            return gg
    def my_read_rb(address):
        with open('address','rb','encoding=utf-8') as ff:
            gg=ff.read()
            return gg
    def my_write(address,gg):
        with open('address', 'w', 'encoding=utf-8') as ff:
            ff.write(gg)
    def my_write_wb(address,gg):
        with open('address', 'wb', 'encoding=utf-8') as ff:
            ff.write(gg)
    def my_read_json(address):
        with open('address') as ff:
            gg=json.load(ff)
            return gg
    def my_write_json(address,gg):
        with open('address', 'w') as ff:
            json.dump(gg,ff)
    
    import  HomeWork
    
    gg='./json1.json'
    fileManager.write_text_file('["de"]',gg)
    print(fileManager.get_text_file_content(gg))
    
    

    相关文章

      网友评论

          本文标题:文件操作作业

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