python 获取当前目录_如何在Python中获取当前的工作目录?

python 获取当前目录

To get the current working directory in Python, there is a library function getcwd() in the os module.

为了在Python中获得当前的工作目录, os模块中有一个库函数getcwd() 。

getcwd() function does not accept any parameter and returns the path of the current working directory as string i.e. it’s return type is <class str>.

getcwd()函数不接受任何参数,并以字符串形式返回当前工作目录的路径,即其返回类型为<class str> 。

Syntax:

句法:

    # import statement
    import os

    # function call
    os. getcwd()

Python代码获取当前工作目录 (Python code to get current working directory)

# Python code to get 
# current working directory

# importing the module
import os

# getting the current path
current_path = os.getcwd()

print("Current working directory is:", current_path)

# printing the type of getcwd() function
print("Type of \'getcwd()\' function is:", type(os.getcwd()))

Output

输出量

Current working directory is: /home/runner/FrenchBrightDaemon
Type of 'getcwd()' function is: <class 'str'>


翻译自: https://www.includehelp.com/python/how-to-get-current-working-directory-in-python.aspx

python 获取当前目录

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值