Loading

关于路径拼接测试脚本,测试加不加/

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/

posted @ 2024-10-12 23:32  一只大学生  阅读(4)  评论(0编辑  收藏  举报