import os # 与操作系统交互模块
import sys # 与python解释器和运行环境相关的函数和变量
import django # django框架模块
# 迭代版(无需更改,要保证此文件是:根目录/scripts/该脚本 即可
cwd = os.getcwd() # D:\d_pycharm_program\workshop_managerment\scripts
root_path = os.path.dirname(cwd) # D:\d_pycharm_program\workshop_managerment
root = os.path.basename(root_path) # workshop_managerment
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # D:\d_pycharm_program\workshop_managerment
sys.path.append(base_dir)
os.environ.setdefault('DJANGO_SETTINGS_MODULE', f'{root}.settings')
django.setup()
# 脚本代码
import datetime
from django.conf import settings
print(os.path.join('/my/', '/upload/')) # /upload/
print(os.path.join('my', 'upload')) # my\upload
print(os.path.join('my', 'upload/')) # my\upload/
print()
print(os.path.join('my/', 'upload/')) # my/upload/
print(os.path.join('my', '/upload/')) # /upload/
print(os.path.join('my/', '/upload/')) # /upload/
print(os.path.join('/my', '/upload/')) # /upload/
print()
print(os.path.join('/my/', '/upload/')) # /upload/
print(os.path.join('/my/', 'upload')) # /upload/
标签:加不加,join,my,upload,拼接,测试,print,path,os
From: https://www.cnblogs.com/cloud-2-jane/p/18461690