O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

os.path

The os.path module is used to manipulate pathnames in a portable manner. It’s imported by the os module.

abspath(path)

Returns an absolute version of the pathname path, taking the current working directory into account. For example, abspath('../Python/foo') might return '/home/beazley/Python/foo'.

basename(path)

Returns the base name of pathname path. For example, basename('/usr/local/python') returns 'python'.

commonprefix(list)

Returns the longest string that’s a prefix of all strings in list. If list is empty, the empty string is returned.

dirname(path)

Returns the directory name of pathname path. For example, dirname('/usr/local/python') returns '/usr/local'.

exists(path)

Returns True if path refers to an existing path. Returns

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required