eEcho blog

is een halte van de gedachte

Python file path

os.path – is een module om de pad te manipuleren.

os.path methods:

abspath(path) # Returns the absolute pathname of a path

basename(path) # Returns filename component of path

dirname(path) # Returns directory component of path

normcase(path) # Normalize capitalization of a name

normpath(path) # Normalize a pathname

split(path) # Split path into (directory, file)

splitdrive(path) # Split path into (drive, pathname)

splitext(path) # Split path into (filename, suffix)

expanduser(path) # Expands ~user components

expandvars(path) # Expands environment vars ’$name’ or ’${name}’

join(p1,p2,…) # Join pathname components

Voorbeelden:

abspath(”../foo”) # Returns “/home/beazley/blah/foo”

basename(”/usr/bin/python”) # Returns “python”

dirname(”/usr/bin/python”) # Returns “/usr/bin”

normpath(”/usr/./bin/python”) # Returns “/usr/bin/python”

split(”/usr/bin/python”) # Returns (”/usr/bin”,”python”)

splitext(”index.html”) # Returns (”index”,”.html”)

Add A Comment

You must be logged in to post a comment.

Home | info@eecho.info | Voorwaarden | Blog