如何在Python中获取当前的工作目录?
要在Python中获取当前的工作目录,有一个库函数getcwd()在os模块中。
getcwd()函数不接受任何参数,并以字符串形式返回当前工作目录的路径,即其返回类型为<classstr>。
语法:
import os # 函数调用 os. getcwd()
Python代码获取当前工作目录
# Python代码获取
# 当前工作目录
# 导入模块
import os
# 获取当前路径
current_path = os.getcwd()
print("Current working directory is:", current_path)
#打印getcwd()函数的类型
print("Type of \'getcwd()\' function is:", type(os.getcwd()))输出结果
Current working directory is: /home/runner/FrenchBrightDaemon Type of 'getcwd()' function is: <class 'str'>
热门推荐
10 医院探望朋友祝福语简短
11 毕业祝福语简短女朋友
12 春节虎年爸妈祝福语简短
13 儿童毕业祝福语 简短6
14 开工仪式横幅祝福语简短
15 孩子日常祝福语大全简短
16 清晨寄语诗句祝福语简短
17 结婚送亲认亲祝福语简短
18 虎年喝酒拜年祝福语简短