
本文共 2126 字,大约阅读时间需要 7 分钟。
Python-������������������
������open()������������������
���Python������open()��������������������������������������������������������������������������� savory ������������������������������������������������
f = open("filename", 'r')f.close()
open()���������������������
������ | ������ |
---|---|
r | ������������ |
w | ������������ |
a | ������������ |
r+ | ��������������� |
b | ��������������� |
rb | ��������������������� |
������������
���������������������������������������������������������������f.closed
���������������������������������������������with
������������������������������������������������������������������
with open("filename", 'r') as f: # ������������ # ������������print(f.closed)
���������������������������
������������������
������
f.read()
������������������������������������������������������f.read(1024)
f.readline()
������������������������������������������'\n'
���������������f.readlines()
���������������������������������������������for���������������������������������������������
for line in f: print(line, end='')
������������
������f.write()
������������������������������������������������������
���������������������
f.tell()
���������������������������f.seek(offset, from_what)
���������������������������������from_what
���������0������������������������������������f.seek(-1, 2) # ���������������������f.seek(3) # ���������������������������������
JSON���������������
���Python������JSON������������������������������������������������������json
���������
JSON������
������
json.dumps()
���Python���������������JSON������������import jsondata = [1, 2, 3]print(json.dumps(data)) # "[1, 2, 3]"
������������������������
with open("data.json", 'w') as f: json.dump(data, f)
JSON������
���������������������JSON���������
data = json.load(f)print(data)
������������������������������������������������Python���������JSON���������������������������������������������������������������������������������������������������������JSON���������������������������������������������������������
发表评论
最新留言
关于作者
