Python | os.fsdecode() method
Last Updated :
25 Jun, 2019
OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.
os.fsdecode()
method in Python is used to decode the specified filename from the filesystem encoding with ‘surrogateescape‘ error handler, or ‘strict‘ on Windows;
Syntax: os.fsdecode(filename)
Parameter:
filename: A path-like object representing an encoded file. A path-like object is either a str or bytes object representing a path.
Return Type: This method returns a string which represents the decoded filename.
Code: use of os.fsdecode() method
import os
filename = b "/home / user / F\xc3\x8e\xe2\x95\x9a\xc3\x88.txt"
decode = os.fsdecode(filename)
print ( "Decoded filename:" , decode)
|
Output:
Encoded filename: b'/home/user/F\xc3\x8e\xe2\x95\x9a\xc3\x88.txt'
Decoded filename: /home/user/FÎ?È.txt
Reference: https://docs.python.org/3/library/os.html#os.fsdecode
Share your thoughts in the comments
Please Login to comment...