Python基础(目录获取转换)

 可用于Python自定义模块的跨目录调用

#返回自身的自身文件的相对路径
    os.path.abspath(__file__)

#返回自身文件的绝对路径
    os.path.abspath(__file__)

#返回上级目录
    os.path.dirname( os.path.abspath(__file__)

#返回上上级目录
    os.path.dirname(os.path.dirname( os.path.abspath(__file__))

#查看环境变量
    sys.path

#添加环境变量
    sys.path.append(BASE_DIR)


发布了62 篇原创文章 · 获赞 16 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_41674452/article/details/104008538