473,326 Members | 2,110 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,326 software developers and data experts.

attribute decorators

Would it not be nice if you could assign decorators to attributes too ?
for example

class C:
@staticattribute
data='hello'

or

class C:
@privateattribute
data='hello'

Jan 6 '07 #1
2 1253
sorry for repost i just found out the news group comp.lang.python is
the same as py*********@python.org :)

On 5 Jan 2007 20:34:54 -0800, gert <ge**********@gmail.comwrote:
Would it not be nice if you could assign decorators to attributes too ?
for example

class C:
@staticattribute
data='hello'

or

class C:
@privateattribute
data='hello'

--
http://mail.python.org/mailman/listinfo/python-list
Jan 6 '07 #2
On Fri, 05 Jan 2007 20:34:54 -0800, gert wrote:
Would it not be nice if you could assign decorators to attributes too ?
for example

class C:
@staticattribute
data='hello'

You can. You just have to write it as:

class C:
data = staticattribute('hello')

(Of course, writing the staticattribute function is a non-trivial problem.)

or

class C:
@privateattribute
data='hello'
That would be written as

class C:
_data = 'hello'

or possibly

class C:
__data = 'hello'

depending on whether you want private attributes to be by convention or by
name-mangling.
--
Steven.

Jan 6 '07 #3

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

Similar topics

4
by: Michael Sparks | last post by:
Anyway... At Europython Guido discussed with everyone the outstanding issue with decorators and there was a clear majority in favour of having them, which was good. From where I was sitting it...
2
by: Guido van Rossum | last post by:
Robert and Python-dev, I've read the J2 proposal up and down several times, pondered all the issues, and slept on it for a night, and I still don't like it enough to accept it. The only reason...
0
by: Michele Simionato | last post by:
Here is a hack to implement attribute access (say for a Web framework) the way I always wanted it to be. I say "hack" since it uses sys._getframe and it sets the locals of a class, which is not...
0
by: Gert Cuykens | last post by:
would it not be nice if you could assign decorators to attributes too ? for example class C: @staticattribute data='hello' or class C:
2
by: Andrew West | last post by:
Probably a bit of weird question. I realise decorators shouldn't be executed until the function they are defined with are called, but is there anyway for me to find all the decorates declared in a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.