Differences between open() and path.open()

Viewed 1532

Regarding the pathlib module in the standard library, is the path.open() method is just a "wrapper" for built-in open() function?

1 Answers

If you read the source code of pathlib.Path.open you'll find that it simply does:

return io.open(str(self), mode, buffering, encoding, errors, newline, opener=self._opener)

and according to io's documentation:

io.open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

This is an alias for the builtin open() function.

So you are correct that pathlib.Path.open is just a wrapper for the built-in open function.

Related