attribute decorators

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gert

    #1

    attribute decorators

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

    class C:
    @staticattribut e
    data='hello'

    or

    class C:
    @privateattribu te
    data='hello'

  • Gert Cuykens

    #2
    Re: attribute decorators

    sorry for repost i just found out the news group comp.lang.pytho n is
    the same as python-list@python.org :)

    On 5 Jan 2007 20:34:54 -0800, gert <gert.cuykens@g mail.comwrote:
    Would it not be nice if you could assign decorators to attributes too ?
    for example
    >
    class C:
    @staticattribut e
    data='hello'
    >
    or
    >
    class C:
    @privateattribu te
    data='hello'
    >
    --

    >

    Comment

    • Steven D'Aprano

      #3
      Re: attribute decorators

      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:
      @staticattribut e
      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:
      @privateattribu te
      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.

      Comment

      Working...