[Tutor] Re: [Pythonmac-SIG] recursive memory

Jack Jansen Jack.Jansen@cwi.nl
Tue, 16 Apr 2002 11:03:47 +0200


On Monday, April 15, 2002, at 11:41 , Christopher Smith wrote:

> I'm making a modification to the walk() function on the Mac so it avoids
> getting caught in an alias loop between folders (i.e. walking a folder
> which has an alias to another folder which has an alias of the first
> folder).  The way I do this is store the file specs in a dictionary.  I
> have two questions.

macpath.walk() (or actually os.path.walk) is explicitly define *not* to 
do special things for symlinks or aliases. But still: the functionality 
is nice, so maybe we should put it in a new function macostools.walk.


> walk(t, f, a) #no dictionary sent so it should start at {}
>
> I need the dictionary to start at {} every time I first give the walk, 
> but
> then want it updated as I go deeper in the walk--so the main script call
> leaves the dictionary off but recursive calls send the modified
> dictionary.  Is this the right way to go about this?

Yes, don't pass visited={}, because it's going to be the visited 
*object* that is modified, so the next call will use the last value of 
visited (as you've undoubtedly noticed:-).

The idiom is to do
def walk(..., visited=None):
	if visited is None:
		visited = {}

> 2)
> I would also like to find out if an alias points to another (unmounted)
> volume.  The only problem is that if the volume is unmounted, the
> ResolveAliasFile routine (or other routines that will give file
> information, like mac.stat()) will prompt me to insert the volume; I 
> would
> like to have the walk be unattended and so would like a way to override
> the insert volume reaction and just know that the alias points to an
> unmounted volume and just skip it.  Is there another way to detect this
> condition without being asked to insert the missing volume?

I can't find anything, also not in the lower level alias handling 
routines (i.e. what is partially exposed via macfs.Alias methods).
--
- Jack Jansen        <Jack.Jansen@oratrix.com>        
http://www.cwi.nl/~jack -
- If I can't dance I don't want to be part of your revolution -- Emma 
Goldman -