Python os.getcwd() Method
Example
Print the current working directory:
#import os module
import os
#create a new
directory
os.mkdir("mydir")
#change the currently
running directory
os.chdir("mydir")
#Print the updated directory
path
print ("Updated directory:" , os.getcwd())
Try it Yourself »
Definition and Usage
The os.getcwd()
method returns the current working directory.
Note: This method returns the path from the system's root directory.
Syntax
os.getcwd()
Technical Details
Return Value: | A str value, representing the current
working directory. |
---|---|
Python Version: | 2.3 |