Python Glossary Русский

all Python 3sysfunction

sys.getfilesystemencoding()

encodings

Returns the encoding Python uses to convert file names and paths between str and OS bytes; usually 'utf-8' on modern systems.

Syntax

sys.getfilesystemencoding()

It concerns only file names, environment variables and command-line arguments, not file contents — those are governed by encoding in open(). On Windows it has been 'utf-8' (not 'mbcs') since Python 3.6. Do not convert paths by hand: os.fsencode() and os.fsdecode() use the right encoding and error handler.

Examples

import sys
print(sys.getfilesystemencoding())  # → ? utf-8
import os, sys
enc = sys.getfilesystemencoding()
err = sys.getfilesystemencodeerrors()
print(os.fsencode('файл.txt') == 'файл.txt'.encode(enc, err))  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy