[Tutor] Decision matrix

Bob Gailer ramrom@earthling.net
Thu Feb 13 10:16:01 2003


--=======2A0C1575=======
Content-Type: text/plain; x-avg-checked=avg-ok-60876147; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit

Let's step back and look at the functionality desired:
if r get subdirectories
if f process files
if d process directories

Sounds like 2 functions, one for files, one for directories, and another to 
expand the subdirectories, each returning a list. How about:

def fList(path, mode):
   if 'r' in mode:
     path = GetSubDirectories(path)
   if 'f' in mode:
     files = Files(path)
   if 'd' in mode:
     directories = Dirs(path)

if the results of doing both Files and Dirs needs to be presented in some 
order other than all files followed by all directories, arrange the 2 lists 
in the desired order.

At 01:30 AM 2/13/2003 -0700, Poor Yorick wrote:
>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)

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625

--=======2A0C1575=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-60876147
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.445 / Virus Database: 250 - Release Date: 1/21/2003

--=======2A0C1575=======--