[파이썬] subprocess `subprocess.cwd`: 현재 작업 디렉터리 확인

To use subprocess.cwd(), you need to import the subprocess module first. Here’s an example:

import subprocess

current_directory = subprocess.cwd()
print("Current working directory:", current_directory)

In the example above, we import the subprocess module and then call the subprocess.cwd() function to get the current working directory. We store the result in the current_directory variable and then print it out using the print() function.

When you run this code, it will display the current working directory on your console like this:

Current working directory: /path/to/your/current/directory

It’s worth noting that subprocess.cwd() returns a string representing the current working directory. This can be useful when you need to perform operations or access files relative to the current directory.

Using the subprocess.cwd() function is a convenient way to ensure that your Python script or application is executing in the correct working directory.