Python – When to use file vs open

You should always use open().

As the 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)”).

Also, file() has been removed since Python 3.0.

Leave a Comment