python获取工作相对路径

人,唯一剥夺不了的,只有知识 / 2025-02-10 / 原文

import os

# 查看当前工作目录
print("Current working directory:", os.getcwd())

# 如果需要切换到脚本所在的目录
script_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(script_dir)