Python 3.0+osfunction
os.getcwdb
os — working directory
Return the current working directory as bytes.
Syntax
os.getcwdb()
Use it when the directory name does not decode in the current filesystem encoding: you get the raw bytes. In ordinary code getcwd is enough — on Unix it keeps such names by mapping undecodable bytes to surrogates, and os.fsencode restores the original bytes. Since Python 3.8 Windows uses UTF-8 here.
Examples
import os
print(isinstance(os.getcwdb(), bytes)) # → True
print(os.path.isabs(os.getcwdb().decode())) # → True (это абсолютный путь текущего каталога)
print(os.getcwdb().decode() == os.getcwd()) # → True (то же значение, только в str)
print([n.decode() for n in os.listdir(os.getcwdb())] == os.listdir(os.getcwd())) # → True (байтовый путь даёт байтовые имена)
print(os.getcwdb() == os.getcwd()) # → False (bytes и str не равны никогда)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy