Python Basics-File manipulation

Source: Internet
Author: User
Tags readline

‘‘‘
Unicodedecodeerror: ' GBK ' codec can ' t decode byte 0x80 in position 106:illegal multibyte sequence
Encoding= "Utf-8"
Windows defaults to using the GBK

‘‘‘
#data =open ("Chaochao", encoding= "Utf-8"). Read ()
‘‘‘
F=open ("Chaochao", ' R ', encoding= "Utf-8") #赋值给f文件句柄: Contains the file name, character set, size, and in-memory location read-only
D=open ("Chaochao", ' W ', encoding= "Utf-8") #赋值给f文件句柄: Contains the file name, character set, size, and location in memory only new write (overwrite)
E=open ("Baobao", ' a ', encoding= "Utf-8") #赋值给f文件句柄: Contains the file name, character set, size, and location appended in memory


Data=f.read ()
Data2=f.read ()

Print (data)
Print ("------------>data-------------------------------------------------%s-------"%data2)

Print (data)
D.write ("I love Beijing Tian ' an door, I love baby, \ n")
E.write ("Henan people in Shanghai")
F.close ()
D.close ()
E.close ()
‘‘‘
# #high
# F=open ("Chaochao", ' R ', encoding= "Utf-8")
# count=0
# i=0
# Print (F.tell ()) # Tell by character Count
# F.seek (140)
# Print (F.readline ())
# Print (F.tell ()) # Tell by character Count
# Print (F.readline ())
# Print (F.tell ()) # Tell by character Count
# print (f.encoding) #打印文件编码
# Print (F.fileno ()) #返回句柄在文件系统中的编号
# # # # # # # *able is the ability to determine if the function can be manipulated
# Print (F.flush ()) #默认缓存达到指定大小写入内存 Force write memory


#
# for line in F: #打印内存是保存一行 convert Text to counter
# if count==9:
# i + = 1
# continue
#
# Print (I,line.strip ())
# count + = 1

#low Loop
‘‘‘
F=open ("Chaochao", ' R ', encoding= "Utf-8")
#for line in F.readlines ():
For Index,line in Enumerate (F.readlines ()):
If index = = 9: #跳打第十行
Print ("---------------I am Split Line--------------------")
Continue
Print (Line.strip ()) #strip is to remove line breaks, and spaces
# for I in range (5):
# Print (F.readline ())



‘‘‘

#f =open ("Chaochao", ' r+ ', encoding= "Utf-8") #追加方式打开 Read and write
#f =open ("Chaochao", ' w+ ', encoding= "Utf-8") #追加方式打开 Read and write
# F=open ("Chaochao", ' RB ') #以二进制形式打开
#
# Print (F.readline ())
# Print (F.readline ())
# Print (F.readline ())
# print ("-----------------------------------Woshifengexian-------------")
# Print (F.readline ())
# Print (F.tell ()) #打印光标
# #f. Write ("Heheheheehehehehehehehehehehe--------------------------------")
# Print (F.readline ())
#
# F=open ("Chaochao", ' R ', encoding= "Utf-8")
# F_new=open ("chaochao11111", "', encoding=" Utf-8 ")
#
# for line in F:
# if "Hehhehehe" ==line:
# line = Line.replace ("Hehhehehe", "Woshi Wanyachao")
# F_new.write (line)
# F.close ()
# Print (f_new)
# F_new.close ()
# with open ("Chaochao", ' R ', encoding= "Utf-8") as f,\ multiple files can be opened simultaneously
# Open ("Chaochao", ' R ', encoding= "Utf-8") as D:
# for line in F:
# if
#

Python Basics-File manipulation

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.