Re: On properties, use object instead?

Lenard Lindstrom <[email protected]>
Newsgroups gmane.comp.lang.prothon.user
Message-ID <Mahogany-0.66.0-4294693797-20040708-102303.00@pop3.norton.antivirus>
On Thu, 8 Jul 2004 09:10:15 +0100 (BST) Mukhsein Johari <[email protected]> wrote:

> Mark,
> I'm not sure if objects have set_, get_ methods but if
> they did, we would not need prop keyword to implement
> properties.
> 
> Simply (using the example in the tutorial wiki):
> 
> O>> object Widget:
> ...    price = 76
> ...    tax   = 2.12
> ...
> 2.12
> O>> w = Widget()
> <Object:c08db8>
> O>> w.tax
> 2.12
> O>> with Widget:
> ...    object tax:        # change tax to a 'property'
> ...       def get_():     # define get_ method
> ...          return self.price * 0.03
> ...
> O>> w.tax
> 2.28
> O>> Widget.price = 82
> 82
> O>> w.tax
> 2.46
> O>> w.tax = 3
> 
> Uncaught exception:
> --- File: wtax3-src.txt, line: 1, char: 3
> Type Error, write attempt on an object with no set_
> method.
> 
> O>>
> 
The object level get_, set_ and del_ are for overriding all attribute lookup
on an object like Python's __getattribute__, __setattr__ and __delattr__.
They are part of a wild-card property that acts on any attribute.

Lenard Lindstrom
<[email protected]>
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.