YouTip LogoYouTip

Os Getcwd

# Python2.x Python os.getcwd() Method [![Image 3: Python File Methods](#) Python OS File/Directory Methods](#) * * * ### Overview The os.getcwd() method is used to return the current working directory. ### Syntax The syntax format of the **getcwd()** method is as follows: os.getcwd() ### Parameters * None ### Return Value Returns the current working directory of the process. ### Example The following example demonstrates the use of the getcwd() method: ## Example #!/usr/bin/python # -*- coding: UTF-8 -*- import os,sys # Switch to the "/var/www/html" directory os.chdir("/var/www/html") # Print the current directory print"Current working directory. : %s" % os.getcwd() # Open "/tmp" fd =os.open("/tmp",os.O_RDONLY) # Use the os.fchdir() method to change the directory
← Linux Comm Bzip2Os Getcwdu β†’