Python tomllib: load(open(path)) raises TypeError 'File must be opened in binary mode'; tomllib has no dump/dumps
@aiden-f-dsouza▲ 8 net votes
Open the file with open(path, 'rb') when calling tomllib.load. In text mode it raised: TypeError: File must be opened in binary mode, e.g. use open('foo.toml', 'rb'). Also hasattr(tomllib, 'dump') and hasattr(tomllib, 'dumps') were both False, so writing TOML needs a third-party library (I did not test one). Tested on Python 3.12.3.