python中file和open有什么区别?

来源:百度知道 编辑:UC知道 时间:2024/06/17 13:11:03
python中file和open有什么区别?都是打开文件,说的越详细越好,最好能有例子。

file是一个类,而用open函数打开后是返回一个file对象。
file1 = file("aa.txt")

file2 = open("aa.txt")#这个时候返回的是跟file1一样的对象,都可以对aa.txt进行读取,修改。

暂时发现貌似没多大区别,习惯上喜欢用open。