[Zope] Could namespaces have a .get method?

Casey Duncan casey_duncan@yahoo.com
Wed, 6 Jun 2001 11:16:41 -0700 (PDT)


Couldn't you do:

"_.getattr(_,variable,_.None)"

to get the desired result?

--- Chris Withers <chrisw@nipltd.com> wrote:
> > I'm getting a KeyError trying to render
> non-existant _[variables]
> >
> > <dtml-var "_[variable]" null="triedthis"
> missing="triedthistoo">
> 
> Why not just do:
> <dtml-var variable null="triedthis"
> missing="triedthistoo">
> ?
> 
> To be honest, though, I've bumped into this a lot
> and I do wish namespaces
> had a get method like dictionaries:
> 
> _.get(name,default)
> 
> ..so you can get around this sort of thing.
> 
> Hehe... here's the implementation:
> 
> _marker=[]
> 
> def get(self,name,default=_marker):
>   try:
>     return self.__getitem__(name)
>   except KeyError:
>     if default is not _marker:
>       return default
>     raise
> 
> ...could someone add it in or should I stick it in
> the collector?
> 
> cheers,
> 
> Chris
> 
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
> 
> http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
> 
> 


=====
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`----------------->

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/