【python】文件的操作2,,哦哦哈嘿嘿嘿嘿f=o
【python】文件的操作2,,哦哦哈嘿嘿嘿嘿f=o
哦哦哈嘿嘿嘿嘿
f=open("d:\\a100.txt",mode="r+",encoding=‘UTF-8‘)
ff=f.read(3)
print(ff)
f.close()
#哦哦哈
-----------------------------------------------------------------------------------------
f=open("d:\\a100.txt",mode="r+",encoding=‘UTF-8‘)#附近的二哥
f.seek(3)#utf格式,一个中文3个字节,前面怀疑空一个.
ff=f.read()
print(ff)
f.close()
附近的二哥
f=open("d:\\a100.txt",mode="r+",encoding=‘UTF-8‘)
f.seek(6)
ff=f.read()
print(ff)
f.close()
近的二哥
--------------------------------------------------------------------------
附近的二哥哈
f=open("d:\\a100.txt",mode="a+",encoding=‘UTF-8‘)
f.write("哈")
g=f.tell()
f.seek(g-3)
ff=f.read()
print(ff)
f.close()
#哈
------------------------------------------------------------------------------
f=open("d:\\a100.txt",mode="r+",encoding=‘UTF-8‘)
ff=f.readlines()
print(ff)
f.close()
[‘\ufeff附近的二哥哈\n‘, ‘日出香炉生紫嫣\n‘, ‘元靠谱不挂前程\n‘]
------------------------------------------------------------------------------
f=open("d:\\a100.txt",mode="r+",encoding=‘UTF-8‘)
for i in f:
print(i)
附近的二哥哈
日出香炉生紫嫣
元靠谱不挂前程
--------------------------------------------------
with open("d:\\a100.txt",mode="r+",encoding=‘UTF-8‘) as ff:
print(ff.read())
附近的二哥哈
日出香炉生紫嫣
元靠谱不挂前程
----------------------------------------------------------------------------------------------
打开多个文件
with open("d:\\a100.txt",mode="r+",encoding=‘UTF-8‘) as ff,\
open("d:\\a101.txt",mode="r+",encoding=‘UTF-8‘) as ff1:
print(ff.read(),ff1.read())
附近的二哥哈
日出香炉生紫嫣
元靠谱不挂前程
日照香炉
生紫烟
【python】文件的操作2
评论关闭