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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…