Chapter 13. Implementation Support Modules

The dospath Module

The dospath module, shown in Example 13-1, provides os.path functionality on DOS platforms. You can also use it to handle DOS paths on other platforms.

Example 13-1. Using the dospath Module

File: dospath-example-1.py

import dospath 

file = "/my/little/pony"

print "isabs", "=>", dospath.isabs(file)
print "dirname", "=>", dospath.dirname(file)
print "basename", "=>", dospath.basename(file)
print "normpath", "=>", dospath.normpath(file)
print "split", "=>", dospath.split(file)
print "join", "=>", dospath.join(file, "zorba")

isabs => 1
dirname => /my/little
basename => pony
normpath => \my\little\pony
split => ('/my/little', 'pony')
join => /my/little/pony\zorba

Note that Python’s DOS support can use both forward ( / ) and backward slashes ( \ ) as directory separators.

Get Python Standard Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.