[Tutor] Builtin "property" decorator hiding exceptions

Andreas Kostyrka andreas at kostyrka.org
Thu Apr 19 08:26:57 CEST 2007


I know, this might sound stupid, but property is not a decorator. :)

Andreas

* Jacob Abraham <jakieabraham at yahoo.com> [070419 08:25]:
> Hi,
> 
>    The sample script below throws the exception "AttributeError: input" rather than the expected exception "AttributeError: non_existent_attribute".  
> 
>    Please help me write a decorator or descriptor of my own that fixes the issue.
> 
> class Sample(object):
>     def __init__(self):
>         self.arguments = {}
> 
>     def __getattr__(self, name):
>         ret_val = self.arguments.get(name, None)
>         if ret_val != None: return ret_val
>         raise AttributeError, name
>     
>     @property
>     def input(self):
>         self.non_existent_attribute
>     
> 
> sample = Sample()
> sample.input
> 
> 
> Regards,
> Jacob Abraham
> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list