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 获取当前目录