如何 Open/Read/Write Python 父目录中的文件夹中的文件?

How to Open/Read/Write Files in a Folder in Parent Directory in Python?

我想要 open/read/write 位于父目录的文件夹中的文件:

这是我的文件树:

HiLo v2.00/
┣ Data/
┣ Files/
┃ ┣ __pycache__/
┃ ┃ ┣ __init__.cpython-38.pyc
┃ ┃ ┣ config.cpython-38.pyc
┃ ┃ ┣ menu.cpython-38.pyc
┃ ┃ ┗ score.cpython-38.pyc
┃ ┣ __init__.py
┃ ┣ config.py
┃ ┣ game.py
┃ ┣ menu.py
┃ ┗ score.py
┣ __pycache__/
┃ ┣ config.cpython-38.pyc
┃ ┣ game.cpython-38.pyc
┃ ┗ score.cpython-38.pyc
┗ setup.py

我想要 Data/ 文件夹中的 open/read/write 个文件。我如何从 Files/menu.py 打开它?

这听起来像你要找的东西

连同https://stackabuse.com/introduction-to-the-python-pathlib-module/

from pathlib import Path
d = Path(__file__).resolve().parents[1]
print(d)
d = d / 'Data' / 'yourfile.txt'
print(d)
with d.open() as file:
    print(file.read())