By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,675 Members | 2,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,675 IT Pros & Developers. It's quick & easy.

attribute decorators

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.