Python 2 documentation recommends against the usage of file(), and Python 3 removes it entirely. open() can do everything file() can do and using it is identical apart from having a few extra features.
Also, it's usually recommended to use the context manager pattern when dealing with files to prevent resource leaks. If you don't close the files, they will stick around in the process' file descriptor table. When using a context manager, the file is closed at the end of the scope.Alternatively the files could just be closed manually but this is easier and cleaner.
Python 2 documentation recommends against the usage of
file()
, and Python 3 removes it entirely.open()
can do everythingfile()
can do and using it is identical apart from having a few extra features.Also, it's usually recommended to use the context manager pattern when dealing with files to prevent resource leaks. If you don't close the files, they will stick around in the process' file descriptor table. When using a context manager, the file is closed at the end of the scope.Alternatively the files could just be closed manually but this is easier and cleaner.