import os
# 获取当前文件的绝对路径
current_file_path = os.path.abspath(__file__)
print("当前文件的绝对路径是:", current_file_path)
# 获取当前文件所在的目录
current_directory = os.path.dirname(os.path.abspath(__file__))
print("当前文件所在的目录是:", current_directory)
os.path.abspath(__file__):获取当前 Python 文件的绝对路径。os.path.dirname(os.path.abspath(__file__)):获取当前 Python 文件所在的目录路径。这段代码可以帮助你获取当前 Python 文件的绝对路径及其所在的目录路径。
上一篇:python 函数参数
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站