陈粒

Python的函数式编程与内置函数9-文件处理

╄→尐↘猪︶ㄣ 提交于 2020-02-14 18:03:00
读取文件 r 1.打开文件 f = open ( '陈粒' ) data = f . read ( ) print ( data ) f = open ( '陈粒' , encoding = 'utf8' ) data = f . read ( ) print ( data ) 2. 打开文件open默认是写 f = open ( '陈粒' , encoding = 'utf8' ) #r w a f = open ( '陈粒' , 'r' , encoding = 'utf-8' ) #r 只读模式,w 只写 , a print ( f . readable ( ) ) 3. f = open ( '陈粒' , encoding = 'utf-8' ) print ( '1' , f . readline ( ) , end = '' ) #一次读一行 print ( '2' , f . readline ( ) , ) #一次读一行 print ( '3' , f . readline ( ) , ) #一次读一行 print ( '4' , f . readline ( ) , ) #一次读一行 print ( '5' , f . readline ( ) , ) #一次读一行 print ( '6' , f . readline ( ) , ) #一次读一行 print (