I know this question sounds very basic. But I can’t find it using Google. I know that there are dictionaries that look like
o = {
'a': 'b'
}
and they’re accessed with o['a']. But what are the ones that are accessed as o.a called? I know they exist because I’m using optparse library and it returns an object accessible like that.
You can not access dicts using the ‘.’ unless you implement your own dict type by deriving from dict and providing access through the ‘.’ notation by implementing the
__getattribute__()API which is in charge for performing attribute style access.See http://docs.python.org/reference/datamodel.html#object.__getattribute__