# -*- coding: utf-8 -*-
# author:wyatt
# @time:2021/10/14 20:41
import os

# 获取当前文件的绝对路径
print(os.path.abspath(__file__))

# 获取某个文件的目录
file_path = os.path.abspath(__file__)
file_dir = os.path.dirname(file_path)
print(file_dir)

# 路径拼接:相当于在两个字符串中间加了反斜杠\
# 字符串的拼接: D:\pylearn\test_shizhan\上课代码 + '\' + 总结.md
md_file = os.path.join(file_dir, '总结.md')
print(md_file)

项目代码示例:

"""配置选项"""

import os

# 获取config.py当前文件的路径
current_path = os.path.abspath(__file__)


# 配置文件目录的路径
config_dir = os.path.dirname(current_path)


# 项目的根目录
root_dir = os.path.dirname(config_dir)


# 测试数据的路径 data/
data_dir = os.path.join(root_dir, 'data')


# 测试用例的文件路径
case_file = os.path.join(data_dir, 'cases.xlsx')

 

posted on 2021-10-15 21:36  熊猫星人  阅读(126)  评论(0)    收藏  举报