Facades can often be found in Python's source code.
The isdir
function found in the os.path
module serves as a Facade outshining work stat
and os.stat
modules. Internally isdir
calls the os.stat
function and that function in turn calls the stat()
system call on the given path. This system call returns a structure with members, namely:
st_mode
: This indicates some protection bitsst_size
: This is the size of the file, in bytesst_atime
: This is the time of the most recent access
stat.S_ISDIR
internally applies a bit mask S_IFMT
to detect if the file passed by is actually a directory. This looks pretty confusing, but the good news is that the end user of this function does not need to know these intricacies. The user just needs to know about the isdir
function.
def isdir(s): """Return true if the pathname refers to an existing directory.""" try: st = os.stat(s) except os.error: return False return stat.S_ISDIR(st.st_mode)
Another example is...