On this page
os.fspath
Prev: os.fsencode | Up: os | Next: os.getcwd
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.fspath
Tags: #public #python3 #stdlib #os
Import
import os
from os import fspath
Signature & Overview
os.fspath(path)
Return the file system path representation of the object.
Usage
import os
from pathlib import Path
assert os.fspath(Path("a/b.txt")) == str(Path("a/b.txt"))
assert os.fspath("raw.txt") == "raw.txt"
Gotchas
- Accepts
str,bytes, or anyos.PathLike(Path): Standard way for library functions to accept bothstrandPatharguments cleanly.
REPL Inspect
from os import fspath
help(fspath)
Linked from
Related notes
- tuts/python3/stdlib_module/os/fsencode Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/getcwd 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