- 论坛徽章:
- 0
|
很基础的东西,但刚学的时候,我是很迷惑。到底操作文件用那个方法。
看看python的介绍:
两种都是build-in function
file( filename[, mode[, bufsize]])
Constructor function for the file type, described further in section 3.9, ``File Objects''. The constructor's arguments are the same as those of the open() built-in function described below.
When opening a file, it's preferable to use open() instead of invoking this constructor directly. file is more suited to type testing (for example, writing "isinstance(f, file)").
open( filename[, mode[, bufsize]])
Open a file, returning an object of the file type described in section 3.9, ``File Objects''. If the file cannot be opened, IOError is raised. When opening a file, it's preferable to use open() instead of invoking the file constructor directly.....
所以这么来解释
file是file类型的构造函数,虽然也可以打开文件,但更提倡使用open的方式来使用。两者应该没有本质的区别 ,所以大家打开文件还是用open(),应该规范一些。
我现在就是这样理解的。不知道是否正确
[ 本帖最后由 pumaboyd 于 2008-9-9 18:26 编辑 ] |
|