import os
# 获取当前工作目录
current_path = os.getcwd()
print("当前工作目录:", current_path)
os 是 Python 的标准库之一,提供了与操作系统交互的功能。os.getcwd() 函数用于获取当前工作目录(即当前脚本运行的目录)。current_path 变量存储了当前工作目录的路径。print 语句用于输出当前工作目录的路径。如果你需要获取当前脚本所在的文件路径,可以使用以下代码:
import os
# 获取当前脚本所在的文件路径
current_file_path = os.path.dirname(os.path.abspath(__file__))
print("当前脚本所在路径:", current_file_path)
os.path.abspath(__file__) 获取当前脚本的绝对路径。os.path.dirname() 获取路径中的目录部分,去掉文件名。上一篇:python pillow
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站