[Tutor] Decision matrix
Poor Yorick
gp@pooryorick.com
Thu Feb 13 03:29:11 2003
alan.gauld@bt.com wrote:
>>eac
>>
>
>Sounds like the definition of a dictionary to me...
>
Two problems with using a dictionary:
1. I would like the flags to be accepted in any order.
2. If I come up with other flags in the future, I would like to deal
with them in the most simple possible manner. Adding an exponentially
larger number of permutations as dictionary keys doesn't seem like a
good method.
The solution I've been thinking of today is to code a list of possible
functions for each flag and then find the intersection of the lists
indicated by the flags passed into the function. Here is a pseudocode
example:
def fList(path, mode):
'''return a list of files, folders, or both, optionally including
subdirectories'''
#flag tuples
f = (Files, FilesS, FilesDirs, FilesDirsS)
d = (Dirs, DirsS, FilesDirs, FilesDirsS)
r = (DirsS, FilesS, FilesDirsS)
choice = Intersection(f, d, r)
return choice(path)
Poor Yorick
gp@pooryorick.com