I see people occasionally open a file handler with the file built in; Particularly in the pyyaml documentation.
This confuses me as the Python documentation states:
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)).
So this seems to imply that file and open do the same thing, yet file is a type, whereas open is a function:
>>> open
<built-in function open>
>>> file
<type 'file'>
And they both return a file type object:
>>> open('/dev/zero')
<open file '/dev/zero', mode 'r' at 0x7f9bb0b964b0>
>>> file('/dev/zero')
<open file '/dev/zero', mode 'r' at 0x7f9bb0b96540>
Is there a difference of using one or the other?
Are there caveats or advantages to using file vs open to open files?