On this page
os.fsencode
Prev: os.fsdecode | Up: os | Next: os.fspath
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.fsencode
Tags: #public #python3 #stdlib #os
Import
import os
from os import fsencode
Signature & Overview
os.fsencode(filename)
Encode filename (an os.PathLike, bytes, or str) to the filesystem encoding with 'surrogateescape' error handler, return bytes unchanged.
Usage
import os
assert os.fsencode("notes.txt") == b"notes.txt"
assert os.fsencode(b"notes.txt") == b"notes.txt"
Gotchas
- Converts
str/os.PathLiketo filesystembytes: Handy when passing paths toctypesor low-level C APIs.
REPL Inspect
from os import fsencode
help(fsencode)
Linked from
Related notes
- tuts/python3/stdlib_module/os/fsdecode Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/fspath 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