日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Python?獲取當前路徑3種方法_python

作者:大小寶 ? 更新時間: 2023-03-28 編程語言

1、os.path 方法

# -*- coding: utf-8 -*-
# !/usr/bin/python

import os
import sys

current_directory = os.path.dirname(os.path.abspath(__file__))

print(current_directory)

輸出:

Alt

2、os.path.abspath 方法

# -*- coding: utf-8 -*-
# !/usr/bin/python

import os
import sys

root_path = os.path.abspath(os.path.dirname(current_directory) + os.path.sep + ".")
sys.path.append(root_path)

print(sys.path[0])

輸出:

Alt

3、os.getcwd 方法

currentPath = os.getcwd().replace('\\','/')    # 獲取當前路徑
print(currentPath)

輸出:

Alt

原文鏈接:https://blog.csdn.net/hongzhen91/article/details/103274923

欄目分類
最近更新