Python os.getcwdb() Method
os.getcwdb() Overview
The os.getcwdb() method is used to return a byte string (bytestring) representing the current working directory.
A ByteString is a UTF-8 string that can correspond to all possible byte sequences.
This method was changed in Python version 3.8: the function uses UTF-8 encoding on Windows instead of ANSI.
os.getcwdb() Syntax
The syntax format of the getcwdb() method is as follows.
os.getcwdb()
os.getcwdb() Parameters
- None
os.getcwdb() Return Value
Returns a Unicode object of the current working directory.
os.getcwdb() Demo#1
The following example demonstrates the use of the getcwdb() method:
#!/usr/bin/python3
import os, sys
# Use os.chdir to switch to the "/var/www/html" directory
os.chdir("/var/www/html" )
# Print the current directory
print ("Current working directory os.getcwdb(): %s" % os.getcwdb())
# Open "/tmp"
fd = os.open( "/tmp", os.O_RDONLY )
# Use the os.fchdir() method to modify the directory
os.fchdir(fd)
# Print the current directory
print ("Current working directory os.getcwdb(): %s" % os.getcwdb())
# Close file
os.close( fd )
Output: