Hello, I am not an experienced Python programmer. So I'd like to ask some detail to the syntax I found in sigrok protocol decoders.
I wonder about the syntax or probably syntactic sugar in the libsigrokdecode library. The sigrok protocol decoder API (https://www.sigrok.org/wiki/Protocol_decoder_API) includes the attribute "options" as a tuple consisting of dictionaries. The decoder code itself reads the current options value with a "string index" like in the UART decoder: self.bw = (self.options['data_bits'] + 7) // 8 I want to run my decoder in a plain Python environment to make some tests. Instead of deriving from "srd.Decoder" I can write the decoder class like this: class Decoder: options = ( {'id': 'baudrate', 'desc': 'Baud rate', 'default': 115200}, ) def __init__(self): pass def start(self): if options['baudrate'] == 9600: pass # test the class if __name__ == "__main__": d = Decoder() d.start() If I instantiate the class I get an exception for the first line in the start method: "tuple indices must be integer or slices, not str". What is the magic behind the libsigrok implementation, that allows to use a string to access a specific options value? Is there some Python magic that helps to make the start method running in a plain Python environment? Best regards, Helge
_______________________________________________ sigrok-devel mailing list sigrok-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sigrok-devel