foo[] - mapping or sequence function called first?

anthony baxter (anthony.baxter@aaii.oz.au)
Sat, 04 Feb 1995 00:29:07 +1100

I've been bashing on the Python SNMP interface again, and I've hit a
bit of a snag - one of the objects will offer both subscripting and
the sequence 'item' method - these appear to take the same syntax, ie
foo[1].

I need the mapping subscript syntax for sub-identifiers (eg
a.iso.org.dod.internet.mgmt['mib-2'].interfaces.ifNumber[0].get()
(to pick a pathological example)) and it seems I need the sequence
'item' call to do Jack's suggested

for i in s.interfaces.ifTable.ifEntry:
do_some_tabular_magic()

syntax.

>From fiddling a bit, it appears the way a 'for' loop is done is that
the seq_item function is called with successively higher numbers
until it returns 0. But wont this also then mean on a call, say, of
foo.ifNumber[0], that the sequence_item function might get called?

Testing it shows that the mapping subscript function always gets called
in preference to the sequence item function, but I need to be sure that
this will remain the case.

Thanks,

Confused In Melbourne.