Python full stack development--file operation

Source: Internet
Author: User

#读

1 f=open ('d:\\k.py', encoding='UTF8') 2 print (F.readline ()) 3 print (F.readline ()) 4 print (F.readline ())         #读一行readline5print (f.readable ())         #读全部, converting each line to a list string  6print (F.readlines ())7 f.close ()

#写文件

F=open ( ' li Chen ','w') f.write ('1244\ n43564\ngergre\nghhrt\n') f.writelines (['fsdgfwsdg', ' 3242 '])  # A String f.close () than required

#追加

F=open (' li Chen ','a')   #a mode append f.write ( ' FDHDH ' ) f.write ('hgfbf') f.close ()
#总结加其它
#打开文件模式
R Read-only mode
W Write-only mode (no, create, have, empty content)

A append mode
X write-only mode (no, create, error)
# "+" blending mode
r+ Reading and writing
W Read/write
A write read
x+ Reading and writing
# "B" means operation in bytes
RB or R+b
WB or W+b
AB or A+b
XB or X+b

Python full stack development--file operation

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: info-contact@alibabacloud.com 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.