On this page
os.fsdecode
Prev: os.fork | Up: os | Next: os.fsencode
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.fsdecode
Tags: #public #python3 #stdlib #os
Import
import os
from os import fsdecode
Signature & Overview
os.fsdecode(filename)
Decode filename (an os.PathLike, bytes, or str) from the filesystem encoding with 'surrogateescape' error handler, return str unchanged. On Windows, use 'strict' error handler if the file system encoding is
Usage
import os
assert os.fsdecode(b"notes.txt") == "notes.txt"
assert os.fsdecode("notes.txt") == "notes.txt"
Gotchas
- Lossless round-trip with
fsencode(): Usessurrogateescapeon Unix so non-UTF-8 OS filenames decode without raisingUnicodeDecodeError.
REPL Inspect
from os import fsdecode
help(fsdecode)
Linked from
Related notes
- tuts/python3/stdlib_module/os/fork Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/fsencode Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/os/abort Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/access Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chdir Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chmod Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chown shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/close shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/cpu_count shared tags: #os, #stdlib