python打开文件权限说明
========= =============================================================== Character Meaning --------- --------------------------------------------------------------- 'r' open for reading (default) 'w' open for writing, truncating the file first 'x' create a new file and open it for writing 'a' open for writing, appending to the end of the file if it exists 'b' binary mode 't' text mode (default) '+' open a disk file for updating (reading and writing) 'U' universal newline mode (deprecated) ========= ===============================================================
>>> f = open('d:\\record.txt','w') #如果不存在创建文件
>>> f = open('d:\\record.txt','r') >>> type(f) <class '_io.TextIOWrapper'>>>>
#打印每一样数据
>>> lines = list(f) >>> for each_line in lines: print(each_line) #推荐方式 >>> for each_line in f: print(each_line)
>>> f = open("d:\\record.txt",'w') >>> f.write('i love python') 13 >>> f.close() #关闭文件数据才会冲缓冲区写入文件 >>> f = open("d:\\record.txt",'r') >>> f.read() 'i love python'
权限模式是open的参数
>>> f = open('d:\\record.txt','a') >>> f.write(' i love php too !!') 18 >>> f.close()
>>> f = open('d:\\record.txt','r') >>> f.read() 'i love python i love php too !!' >>>
