Python3 Os Getcwdb
# Python3.x Python3 os.getcwdb() Method
[ Python3 OS File/Directory Methods](#)
* * *
### Overview
The `os.getcwdb()` method is used to return a 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 3.8: the function uses UTF-8 encoding on Windows, instead of ANSI.
### Syntax
The syntax for the `getcwdb()` method is as follows:
os.getcwdb()
### Parameters
* None
### Return Value
Returns a Unicode object representing the current working directory.
### Example
The following example demonstrates the use of the `getcwdb()` method:
## Example
#!/usr/bin/python3
import os,sys
# Change to the "/var/www/html" directory
os.chdir("/var/www/html")
# Print the current directory
print("Current working directory : %s" % os.getcwdb())
# Open "/tmp"
fd =os.open("/tmp",os.O_RDONLY)
# Use the os.fchdir() method to change directory
os.fchdir(fd)
# Print the current directory
print("Current working directory : %s" % os.getcwdb())
# Close the file
os.close( fd )
The output of the above program is:
Current working directory : b'/var/www/html'Current working directory : b'/private/tmp'
[ Python3 OS File/Directory Methods](#)
YouTip