F1 = open (R'E:\Python\Data\data1.txt') # reads the data1.txt file, using the system default buffer size, To read fast, use cache!
f = Open (r'E:\Python\Data\data2.txt','W') F.write ('Hello World!') F.close () F= Open (R'E:\Python\Data\data2.txt','R') P1= F.read (5)#Read 5 bytes FirstP2 = F.read ()#read all the rest.
f.close ()
File_obj.readlines (), File_obj.readline (), File_obj.writelines ()
f = open (R'E:\Python\Data\data3.txt'= F.readlines () # Reads data from a line of files, returns a list of print(cnames) f.close ()
# As a result, readlines () reads the result without removing the line break ['GOOGLE inc\n'nicrosoft corporation\n' Apple inc.\n'Facebook, Inc. ']
#Filename:revcopy.pyF1 = Open (r'E:\Python\Data\data3.txt') # read cnames=F1.readlines () forIinchRange (0, Len (cnames)): Cnames[i]= str (i+1) +'.'+cnames[i]f1.close () F2= Open (R'E:\Python\Data\data3_out.txt','W') # write f2.writelines (cnames) f2.close ()
' Tencent technology company Limited ' = open (R'E:\Python\Data\data3.txt' a+') F.writelines ('\ n') f.writelines (s)f.seek (0, 0) # Move the file pointer to the file header = f.readlines ()print(cnames) f.close ()
Python Learning Notes (15) Get local data with Python