473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Re: Enhanced property decorator

On Aug 25, 8:45*pm, Daniel <miller...@gmail.comwrote:
I've often been frustrated by the inability of the built-in property
descriptor to handle anything other than a read-only property when
used as a decorator. Furthermore, read/write/delete properties take
their doc-string and property definition at a non-intuitive and
awkward place (after the getter/setter/delter functions). The
following are three possible solutions to this problem (inspired by
messagehttp://groups.google.com/group/comp.lang.python/msg/9a56da7ca8ceb7c7).
I don't like the solution in that thread because it uses apply() which
will go away in Python 3.
I didn't read the rest of the thread, but I think Python 2.6 may have
want you want:

class A(object):

@property
def my_prop(): return self._prop

@my_prop.setter
def my_prop(prop): self._prop = prop

@my_prop.deleter
def my_prop(): del self._prop
Aug 26 '08 #1
2 1838
On 25 Aug, 21:52, Benjamin <musiccomposit...@gmail.comwrote:
... I think Python 2.6 may have
want you want:

class A(object):

* * @property
* * def my_prop(): return self._prop

* * @my_prop.setter
* * def my_prop(prop): self._prop = prop

* * @my_prop.deleter
* * def my_prop(): del self._prop
Hmm, interesting. I wonder if it suppports setting the doc-string in a
similar way? I'll have to look into that. Thanks for pointing this
out.

~ Daniel
Aug 26 '08 #2
On Aug 25, 9:00*pm, Daniel <miller...@gmail.comwrote:
On 25 Aug, 21:52, Benjamin <musiccomposit...@gmail.comwrote:
... I think Python 2.6 may have
want you want:
class A(object):
* * @property
* * def my_prop(): return self._prop
* * @my_prop.setter
* * def my_prop(prop): self._prop = prop
* * @my_prop.deleter
* * def my_prop(): del self._prop

Hmm, interesting. I wonder if it suppports setting the doc-string in a
similar way? I'll have to look into that. Thanks for pointing this
out.
It takes the getter's docstring as usual.
>
~ Daniel
Aug 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Ron_Adam | last post by:
I was having some difficulty figuring out just what was going on with decorators. So after a considerable amount of experimenting I was able to take one apart in a way. It required me to take a...
22
by: Ron_Adam | last post by:
Hi, Thanks again for all the helping me understand the details of decorators. I put together a class to create decorators that could make them a lot easier to use. It still has a few glitches...
4
by: Colin J. Williams | last post by:
Is there some way that the user can access the docstring specified for a property? Please see the example below: # propDocTest class A(object): def __init__(self, value): self.value= value...
8
by: lab3terch | last post by:
I have built an enhanced button control which I want to use to capture the number of times the button has been clicked. I have added the new control to a test program but cannot get it to work. The...
0
by: lab3terch | last post by:
I have built an enhanced button control which I want to use to capture the number of times the button has been clicked. I have added the new control to a test program but cannot get it to work. The...
0
by: lab3terch | last post by:
I am using Visual Studio.NET 2003 and have built a enhanced button control (enhbutton) to capture the number of times the button has been clicked. I did the code and did a build. I then added a test...
11
by: king kikapu | last post by:
Hi to all, i am trying to use properties in Python and i am sure i have made something wrong with the below code but i just cannot see what it is. Can anyone please help me on this ? The...
4
by: thomas.karolski | last post by:
Hi, I would like to create a Decorator metaclass, which automatically turns a class which inherits from the "Decorator" type into a decorator. A decorator in this case, is simply a class which...
0
by: Ben Finney | last post by:
Daniel <millerdev@gmail.comwrites: The fact that the 'property' function works as a decorator (in, as you point out, some cases only) is a happy accident. The 'property' function isn't...
14
by: Rafe | last post by:
Hi, I've encountered a problem which is making debugging less obvious than it should be. The @property decorator doesn't always raise exceptions. It seems like it is bound to the class but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.