[파이썬] os 현재 작업 디렉토리 얻기: `os.getcwd()`
To obtain the current working directory in Python, you can simply call the os.getcwd()
function. Here’s an example of how to use it:
import os
# Get the current working directory
current_directory = os.getcwd()
# Print the current working directory
print("Current working directory:", current_directory)
In the above code, we first import the os
module. Then, we use the os.getcwd()
function to retrieve the current working directory and store it in the current_directory
variable. Finally, we print the current working directory using the print()
function.
When you execute the code, you will see the current working directory printed on the terminal or console.
Using the os.getcwd()
function can be useful in various scenarios, especially when you need to work with files or directories in a specific location relative to the current working directory.