The processing speed is faster with the open function. The versatile docecs.open function. Both the readability and simplicity of the source code. In short, it was up to you to use it.
When you are doing "100 language processing knocks" that you all know for practicing python3, I noticed that there are two types of functions that open files (open and codecs.open). Both seem to be often used.
The codecs.open function can open a file encoded in Python2 series. Yeah, maybe it's convenient. I understand that this is the difference in usage (please let me know if you point out).
However, there are some differences in how to write the source code. Let's take a look below.
Let's create a code that reads hoge.txt like the one below.
Execution result ↓
The open function is included in the standard library, so there is no need for special import. The number of lines will be shorter by that amount, but it seems to be unfashionable because the argument name must be specified.
Execution result ↓
You need to import the codecs library. However, one line is short and looks smart because no argument name is specified.
Overwrite 1 million times and compare the speed. The execution was performed 5 times each.
The above measurement results are available. The open function was about 3 times faster. It's like a red comet.
The processing speed is faster with the open function. The versatile docecs.open function. Both the readability and simplicity of the source code. In short, it was up to you to use it.