Python 3.5+tempfilefunction
tempfile.gettempdirb()
directories and paths
The bytes version of gettempdir(): returns the temporary directory as bytes.
Syntax
tempfile.gettempdirb() -> bytes
Use it where paths are handled as bytes (os.listdir(b'...'), bytes arguments to mkstemp): mixing str and bytes in one os.path.join raises TypeError. Ordinary code only needs gettempdir(); the encoding goes through os.fsencode, so unusual characters in the path are not lost.
Examples
import os, tempfile
print(type(tempfile.gettempdirb()).__name__) # → bytes
print(tempfile.gettempdirb() == os.fsencode(tempfile.gettempdir())) # → True
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy