Python File Operations Learning notes

Source: Internet
Author: User

#_ *_ 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 = () only suitable for reading small files
#data1 = () #这个是有问题的, 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
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
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 ()) (10)
Print (F.tell ())
Print (F.readline ())

Python File Operations Learning notes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.