properties with subscripted variables

F

Fabrizio Pollastri

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
 
B

Bruno Desthuilliers

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top