Re: del_, delete_, and properties

"Mark Hahn" <[email protected]>
Newsgroups gmane.comp.lang.prothon.user
Message-ID <[email protected]>
Mark Hahn wrote:

Some corrections on the properties examples...

> FYI:  The property scheme I am implementing is:
>
>     # normal do-nothing property x
>     object Proto1:
>             x_ = DEFAULT
>             def init_():
>                     blah blah blah
>             prop x:                     # same as object x(Prop):
>                     def get_():
>                             return self.x_
>                     def set_(val):
>                             self.x_ = val
>                     def del_(): raise OperationError
>
> obj = Proto1

obj = Proto1()

> y = obj.x   #  replaced with:  y = obj.x.get_{obj}()
> obj.x = y   #  replaced with:  obj.x.set_{obj}( y )
> del obj.x   #  replaced with:  obj.x.del_{obj}()
> obj.attrs_['x']          # not replaced
> obj.attrs_['x'] = y    # not replaced
> del obj.attrs_['x']    # not replaced
>
>     # wild-card properties (like __getattribute__)
>     object Proto1:
>             def get_():
>                     print "you'll get nothing and like it"
>             def set_(): pass
>             def del_(): pass

These wild-card method definitions need formal params like the name of the
attribute.

            def get_(name):
                     print "you'll get nothing and like it"
             def set_(name, val): pass
             def del_(name): pass

> p = Proto1()
> x = p.anything
> you'll get nothing and like it
> print x
> None
> p.asdf = 37
> x = p.asdf
> you'll get nothing and like it
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.