FAQ
Hi,
I work on the python module AVC (http://avc.inrim.it) useful for the
development of applications with GUIs. AVC is based on the property
mechanism: any a variable controlled by AVC is set as a property, so
when it is assigned by the application program, the __set__ function
is called and AVC does its job. This works fine with non sequence
types and with sequence types when are assigned as a whole, without
subscripting. When the assignment has a subscript, the __set__ method
is no more called. This is a limitation from the point of view of AVC.
My goal would be to be able to intercept (trigger a call to a method
of my module) any kind of variable assignment, even if it is a
sequence type with a subscript.
There is a way to reach this result with properties or with other
ways?

Best regards,
F. Pollastri

Search Discussions

  • Bruno Desthuilliers at Aug 26, 2008 at 10:56 am

    Fabrizio Pollastri a ?crit :
    Hi,
    I work on the python module AVC (http://avc.inrim.it) useful for the
    development of applications with GUIs. AVC is based on the property
    mechanism: any a variable controlled by AVC is set as a property, so
    when it is assigned by the application program, the __set__ function
    is called and AVC does its job. This works fine with non sequence
    types and with sequence types when are assigned as a whole, without
    subscripting. When the assignment has a subscript, the __set__ method
    is no more called.
    Nope, but the __get__ method is.
    This is a limitation from the point of view of AVC.
    My goal would be to be able to intercept (trigger a call to a method
    of my module) any kind of variable assignment, even if it is a
    sequence type with a subscript.
    There is a way to reach this result with properties or with other
    ways?
    The code:

    obj.prop[x] = y

    is equivalent to:

    prop = obj.prop
    prop[x] = y

    IOW, you just have to return from prop.__get__ a custom sequence type
    implementing __setitem__ the way you see fit.

    Also, remember that properties are just one possible way to use the
    descriptor protocol to implement computed attributes. You can define
    your own descriptor objects.

    HTH

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 26, '08 at 10:41a
activeAug 26, '08 at 10:56a
posts2
users2
websitepython.org

People

Translate

site design / logo © 2022 Grokbase