#_ *_ Coding:utf-8 _*_
# author Choco
#f = open ("J:\Python\py\contact.txt", encoding= "Utf-8"). Read ()
#print (f) #读取整个文件内容
f = open ("J:\Python\py\contact.txt", "r+", encoding= "Utf-8") #赋值给f, for file handle R Read, W write Open is to create empty file. A = append appended, written on the last side, cannot be read.
#data = F.read () only suitable for reading small files
#data1 = F.read () #这个是有问题的, after opening, reading the pointer at the end of the file, the content is not read.
#print (data)
#print ("-------data1-----%s---")
#print (DATA1) This is a problem.
#f. Write ("\ n li Lei manager 5465 17754684592") #换行写
#for I in range (5):
# Print (F.readline ()) #读五行
#print (F.readlines ())
Count = 0
For line in F:
if Count = = 4:
Count + = 1
Continue
Count +=1
Print (Line.strip ())
F.close ()
"' Bad
For Index,line in Enumerate (F.readlines ()):
If index== 4:
Print ("-------I'm a separator--------") # Not read line fifth
Continue
Print (Line.strip ()) # with strip to remove whitespace and newline characters
F.close ()
‘‘‘
f = open ("Contact.txt", "R", encoding= "Utf-8")
Print (F.tell ()) #目前读的位置
Print (F.readline ())
Print (F.readline ())
Print (F.readline ()) # Tell the number of characters to read
Print (F.tell ())
F.seek (10)
Print (F.tell ())
Print (F.readline ())
Python File Operations Learning notes