[Python-Dev] os.path.walk() lacks 'depth first' option (original) (raw)

Phillip J. Eby pje@telecommunity.com
Mon, 12 May 2003 23:02:24 -0400


At 09:44 PM 5/12/03 -0400, Guido van Rossum wrote:

This sounds like a much more advanced use, typical to a certain style of programming.

Framework programming, for maximal adaptability of third-party code, yes.

Others would do this using hasattr() or three-argument getattr()

I use three-argument getattr() most of the time, actually. However, doesn't 'getattr()' rely on catching AttributeError? I just wanted my example to be explicit.

Your example argues for allowing to distringuish between AttributeError and TypeError, but doesn't convince me that they are totally different beasts.

Sure. My point is more that using exceptions to indicate failed lookups is a tricky business.

I almost wish there was a way to declare the "normal" exceptions raised by an operation; or perhaps to easily query where an exception was raised.

Nowadays, when designing interfaces that need to signal some kind of exceptional condition, I tend to want to have them return sentinel values rather than raise exceptions, in order to distinguish between "failed" and "broken".

I'm sure that this is an issue specific to framework programming and to large team-built systems, though, and not something that bothers the mythical "average developer" a bit. :)