On Fri, May 27, 2005 at 12:08:55PM -0400, Paul Winkler wrote: > On Fri, May 27, 2005 at 11:49:03AM -0400, Jim Fulton wrote: > > BTW, I prefer to code things like this in the following way: > > > > def safe_hasattr(): > > marker = object() > > > > def safe_hasattr(obj, attr): > > return getattr(obj, attr, marker) is not marker > > > > return safe_hasattr > > > > safe_hasattr = safe_hasattr() > > > > This way, there aren't any extra arguments or funny > > globals to confuse matters. (I've seen code that broke > > because people tried to reuse marker definitions accross > > modules.
One more thought... as for "funny globals", it seems to me that a "private" global like __marker = [] results in cleaner code than either your approach or the keyword arg hack. Anybody who imports a __foo name deserves whatever problems they get :-) But of course we don't do it because accessing globals in a method that might be looped over is slow. Which, hopefully, will become a non-issue some day (PEP 267, 268, 280). -- Paul Winkler http://www.slinkp.com _______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )