Python os.fspath() Method
Example
Print the file system representation of a path:
#Import os Library
import os
#print the file system representation of a path
print (os.fspath("../test"))
Try it Yourself »
Definition and Usage
The os.fspath()
method returns the file system representation of a path.
Note: If the value passed in os.fspath()
is not
str or bytes, it calls __fspath__()
which returns the system path representation of an object in
str and bytes object.
Else, a TypeError is raised.
Syntax
os.fspath(path)
Parameter Values
Parameter | Description |
---|---|
path | Required. A path whose file representation is to be found |
Technical Details
Return Value: | A str or bytes value, representing file system path |
---|---|
Python Version: | 3.6 |