Operation Python on the file

Example:

. 1  # Open () function in three, first a file path, an absolute path using the current 
2  # 2 functions as a file in what way open, r is reading read, w is written to write, a is an append additionally 
3  # third function represents the returned data encoded using what is generally used utf-8 or gbk. Note that this is written encoding rather than encode Oh. 
. 4 file1 = Open ( ' ./scores.txt.txt ' , ' R & lt ' , encoding = ' UTF-. 8 ' )
 . 5  # to read the contents placed inside the variable f 
. 6 f = file1.readlines () # function readlines (), i.e. "read by row" 
7  # close the file 
. 8  file1.close ()
 . 9  
10  for I in F:    #For ... in ... with each row of data traversing   
. 11      Data = i.split ()     # string finer cut into a string of 
12 is      Print (Data)         # printed out on

split () the content of each row is divided into a string of a

join () function, the string is combined

 

 

 

Guess you like

Origin www.cnblogs.com/lewuyou/p/11569880.html