I'm using Python 3's pathlib
module, like this:
from pathlib import Path
filename = Path(__file__).parent / "example.txt"
contents = open(filename, "r").read()
But I get this error on some machines:
TypeError: invalid file: PosixPath('example.txt')
But on my machine it works.
pathlib
integrates seemlessly withopen
only in Python 3.6 and later. From Python 3.6's release notes:To get it to work in Python 3.5 and Python 3.6, just convert the object to a string: