Python os.fsdecode() Method
Example
Encode and decode file path:
#Import os Library
import os
#Encode filename
encode =
os.fsencode("/home/testuser/desktop/newfile.txt")
#Print the
encoded filename
print(encodedPath)
#Print the decoded filename
print(os.fsdecode(encodedPath))
Try it Yourself »
Definition and Usage
The os.fsdecode()
method decodes a file path.
This method decodes the filename from the filesystem encoding with 'surrogateescape' error handler, or 'strict' on Windows.
Note: os.fsencode() is the reverse function.
Syntax
os.fsdecode(filename)
Parameter Values
Parameter | Description |
---|---|
filename | Required. The file path to decode |
Technical Details
Return Value: | A str value, representing the decoded
path |
---|---|
Python Version: | 3.2 |
Change Log: | 3.6: Support added to accept objects implementing the os.PathLike interface |