file()

file() 与 open() 用法一致,都是用于打开文件,并对文件进行读写操作,但更推荐使用 open(),Python3 已经不支持 file()

In [1]: with file('1.txt') as fd:
   ...:     data = fd.read()
   ...:     

In [2]: print data
aaa
bbb
ccc

 

 

    

猜你喜欢

转载自www.cnblogs.com/pzk7788/p/10486140.html