我想在python中创建当前工作目录之外的文件.这是我的目录结构.
|--myproject
| |-- gui
| | |-- modules
| | | |-- energy
| | | | |-- configuration
| | | | | |-- working_file.py
| |-- service
| | |-- constants
| | | |-- global_variables.json
Run Code Online (Sandbox Code Playgroud)
我目前正在工作/myproject/gui/energy/configuration/working_file.py,我想在/myproject/service/constantsnamed 下创建一个文件global_variables.json
我试过了
with open("../../../../../service/constants/global_variables.json", 'w') as file_handler:
content = json.load(file_handler)
Run Code Online (Sandbox Code Playgroud)