YouTip LogoYouTip

Python3 Os Fchdir

# Python3.x Python3 os.fchdir() Method [![Image 3: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#) * * * ### Overview The os.fchdir() method changes the current working directory using a file descriptor. Available on Unix. ### Syntax The syntax for the **fchdir()** method is as follows: os.fchdir(fd); ### Parameters * **fd** -- File descriptor ### Return Value This method does not return a value. ### Example The following example demonstrates the use of the fchdir() method: #!/usr/bin/python3import os, sys # First, change to the directory "/var/www/html" os.chdir("/var/www/html" )# Print the current directoryprint ("Current working directory: %s" % os.getcwd())# Open the new directory "/tmp" fd = os.open( "/tmp", os.O_RDONLY )# Use os.fchdir() method to change to the new directory os.fchdir(fd)# Print the current directoryprint ("Current working directory: %s" % os.getcwd())# Close the opened directory os.close( fd ) The output of executing the above program is: Current working directory: /var/www/html Current working directory: /tmp [![Image 4: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#)
← Java Hashmap GetordefaultJava Hashmap Replaceall β†’