path
wrapper moddule for os.path.
Like most others I find the os.path module not very handy. Its too much typing
in most cases many frequently required methods are not instantly at hand. So here
is my approach for a higher level wrapper, neither complete nor heavily tested.
sample
# it gets boring to type over and over the following term to get the path of some
# other file in the same dir as the module you're working with
some_other = os.path.join(os.path.basename(__file__), 'someother.file')
# feels better like this...
some_other = path.replace_file(__file__, 'someother.file')
The path module peovides the following methods:
directory
drive
extension
file
url
Note: this seection needs rework, the functions may or may not work
iterators
relative paths
| is_child(parentpath, childpath, emidiate=False, ignorecase=True) | checks if childpath is a child of parentpath
| | is_samepath(ath1, path2, ignorecase=True) | checks if path1 is the same path as path2
| | html_abspath(pathfrom, pathto) | constructs an absolute path from a html style relative path
| | html_relpath(pathfrom, pathto, ignorecase=True) | constructs a html style relative path to pathto
| | relpath(parentpath, childpath, ignorecase=True) | constructs a relative path to parent
|
attributes
taken from os, os.path and shutil
| common_prefix(paths)] | same as os.path.commonprefix()
| | copy_file(source, dest) | same as shutil.copyfile()
| | exists(path)] | same as os.path.exists()
| | is_dir(path) | same as os.path.isdir()
| | is_file(path) | same as os.path.isfile()
| | is_link(path) | same as os.path.islink()
| | join(*components) | same as os.path.join()
| | list_dir(directory) | same as os.listdir()
| | make_dir(path, recursive=True) | same as os.mkdir(), except for the recursive flag, wich calls os.mkdirs() if set toTrue
| | normpath(path) | same as os.path.normpath()
| | remove_tree(path, ignore_errors=False, onerror=None) | same as shutil.rmtree()
| | walk(directory) | same as os.path.walk()
| | walk_sorted(directory) | same as os.path.walk(), except that directories and files are returned sorted
| | renamesource, dest) | same as os.rename()
| | remove(path) | same as os.remove()
| | stat(path) | same as os.stat()
| | lstatpath) | same as os.lstat()
|
others
win32 specific
Note: to make these functions work, apart from running a windows os the
ctypes module has to be installed
to call the relevant system dlls. The ctypes module will be part of the
python distribution as soon as 2.5 is shipped out.
|