标签:直接 readline pytho odi for 硬盘 adl 大会 pre
with open(r'a.txt',mode='rt',encoding='utf-8') as f :
res1=f.readline()
res2=f.readline()
print(res1)
print(res2)
with open(r'a.txt',mode='rt',encoding='utf-8') as f :
while True:
line = f.readline()
if len(line) == 0:
break
print(line)
with open(r'a.txt',mode='rt',encoding='utf-8') as f:
res=f.readlines()
print(res)
with open('d.txt',mode='wt',encoding='utf-8') as f:
# f.write('1111\n2222\n3333\n')
l=['aaaa\n','bbbbb\n','cccc\n']
# for line in l:
# f.write(line)
f.writelines(l)
with open('h.txt', mode='wb') as f:
l=[
b'111aaa1\n',
b'222bbb2\n',
b'333eee3\n',
]
f.writelines(l)
with open('h.txt', mode='wb') as f:
l=[
bytes('上',encoding='utf-8'),
bytes('中',encoding='utf-8'),
bytes('下',encoding='utf-8')
]
f.writelines(l)
with open('i.txt',mode='wt',encoding='utf-8') as f:
f.write('哈')
f.flush()
f.write('哇')
f.flush()
f.write('呀')
f.flush()
with open('j.txt',mode='wt',encoding='utf-8') as f:
print(f.readable()) #判断文件是否可读
print(f.writable()) #判断文件是否可写
print(f.encoding) #文件的编码方式
print(f.name) #文件名
标签:直接 readline pytho odi for 硬盘 adl 大会 pre
原文地址:https://www.cnblogs.com/zhangtieshan/p/12508192.html