On this page
posixpath.basename
Prev: posixpath.abspath | Up: posixpath | Next: posixpath.commonpath
Rel: posixpath.abspath, posixpath.commonpath, posixpath.commonprefix, posixpath.dirname
Ref: docs.python.org — posixpath.basename
Tags: #public #python3 #stdlib #posixpath
Import
import posixpath
from posixpath import basename
Signature & Overview
posixpath.basename(p)
Returns the final component of a pathname
Usage
import posixpath
assert posixpath.basename('/usr/local/bin/python3') == 'python3'
Gotchas
- Trailing slash returns
'':posixpath.basename('/a/b/') == ''.
REPL Inspect
from posixpath import basename
help(basename)
Linked from
- tuts/python3/stdlib_module/posixpath
- tuts/python3/stdlib_module/posixpath/abspath
- tuts/python3/stdlib_module/posixpath/commonpath
- tuts/python3/stdlib_module/posixpath/commonprefix
- tuts/python3/stdlib_module/posixpath/dirname
- tuts/python3/stdlib_module/posixpath/exists
- tuts/python3/stdlib_module/posixpath/expanduser
- tuts/python3/stdlib_module/posixpath/expandvars
- tuts/python3/stdlib_module/posixpath/getatime
- tuts/python3/stdlib_module/posixpath/getctime
- tuts/python3/stdlib_module/posixpath/getmtime
- tuts/python3/stdlib_module/posixpath/getsize
- tuts/python3/stdlib_module/posixpath/isabs
- tuts/python3/stdlib_module/posixpath/isdevdrive
- tuts/python3/stdlib_module/posixpath/isdir
- tuts/python3/stdlib_module/posixpath/isfile
- tuts/python3/stdlib_module/posixpath/isjunction
- tuts/python3/stdlib_module/posixpath/islink
- tuts/python3/stdlib_module/posixpath/ismount
- tuts/python3/stdlib_module/posixpath/join
- tuts/python3/stdlib_module/posixpath/lexists
- tuts/python3/stdlib_module/posixpath/normcase
- tuts/python3/stdlib_module/posixpath/normpath
- tuts/python3/stdlib_module/posixpath/realpath
- tuts/python3/stdlib_module/posixpath/relpath
- tuts/python3/stdlib_module/posixpath/samefile
- tuts/python3/stdlib_module/posixpath/sameopenfile
- tuts/python3/stdlib_module/posixpath/samestat
- tuts/python3/stdlib_module/posixpath/split
- tuts/python3/stdlib_module/posixpath/splitdrive
- tuts/python3/stdlib_module/posixpath/splitext
- tuts/python3/stdlib_module/posixpath/splitroot
Related notes
- tuts/python3/stdlib_module/posixpath/abspath Linked here; links to this page; shared tags: #posixpath, #stdlib
- tuts/python3/stdlib_module/posixpath/commonpath Linked here; links to this page; shared tags: #posixpath, #stdlib
- tuts/python3/stdlib_module/posixpath/commonprefix Linked here; links to this page; shared tags: #posixpath, #stdlib
- tuts/python3/stdlib_module/posixpath/dirname Linked here; links to this page; shared tags: #posixpath, #stdlib
- tuts/python3/stdlib_module/posixpath Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/posixpath/exists links to this page; shared tags: #posixpath, #stdlib
- tuts/python3/stdlib_module/posixpath/expanduser links to this page; shared tags: #posixpath, #stdlib
- tuts/python3/stdlib_module/posixpath/expandvars links to this page; shared tags: #posixpath, #stdlib
- tuts/python3/stdlib_module/posixpath/getatime links to this page; shared tags: #posixpath, #stdlib
- tuts/python3/stdlib_module/posixpath/getctime links to this page; shared tags: #posixpath, #stdlib