scripts icon indicating copy to clipboard operation
scripts copied to clipboard

推荐作者使用pathlib库

Open kfcx opened this issue 4 years ago • 0 comments

原始且麻烦写法

示例配置文件路径

import os BASE_DIR = os.path.split(os.path.abspath(sys.argv[0]))[0] EXAMPLE_CONFIG_PATH = os.path.join(BASE_DIR, 'conf/.config_example.yaml')

输出结果:C:\Users\23914\Desktop\jd_py-master\conf/.config_example.yaml

新式且方便简洁写法 import pathlib BASE_DIR = pathlib.Path().absolute() EXAMPLE_CONFIG_PATH = BASE_DIR / 'conf/.config_example.yaml'

输出结果:C:\Users\23914\Desktop\jd_py-master\conf.config_example.yaml

细品,只是给个建议

kfcx avatar Dec 11 '21 10:12 kfcx