封装文件的读写操作,写操作,写入需要写入文件的内容和地址;读操作,写入需要读取的文件地址。
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))
网友评论