The ntpath Module

The ntpath module (see Example 13-3) provides os.path functionality on Windows platforms. You can also use it to handle Windows paths on other platforms.

Example 13-3. Using the ntpath Module

File: ntpath-example-1.py

import ntpath

file = "/my/little/pony"

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

isabs => 1
dirname => /my/little
basename => pony

normpath => mylittlepony
split => ('/my/little', 'pony')
join => /my/little/ponyzorba

Note that this module treats both forward slashes ( / ) and backward slashes ( ) as directory separators.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.124.177