📜  python 打开相对于脚本位置的文件 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:03.283000             🧑  作者: Mango

代码示例1
import os

path = 'a/relative/file/path/to/this/script/file.txt'

with open(os.path.join(os.path.dirname(__file__), path), 'r') as input_file:
    content = input_file.read()