简体   繁体   中英

Query property name within property getter and setter method

there is a generic function to create properties. It returns the property getter and setter.

See eg line 205.

https://github.com/pymeasure/pymeasure/blob/master/pymeasure/instruments/instrument.py

This function is used to create properties.

See eg line 90

https://github.com/pymeasure/pymeasure/blob/master/pymeasure/instruments/agilent/agilent34450A.py

I need to change the attributes, eg ":READ?" to be replaced by ":MEAS:DC:CURR?", of the property at runtime, to eg support different instruments having the same property but different property attributes. I need to do this for the object and not for the class because I want to use different instruments at the same time, so same class but different objects.

In order to generically identify the attribute to be replaced and, for example, to select it from a data class, it would be nice if the property getters and setters could query the name of the property in which they were called.

Is there an easy way to do this?

These are class attributes, so you should be able to reassign them after instantiating the class. For example, something like:

instrument = Agilent34450A(Instrument)
instrument.current = Instrument.measurement(":MEAS:DC:CURR?", """new description""")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM