Assuming self.dname
is a dictionary:
self.dname[x][0]
x
is an "index" variable - you are using it to find the data you want. Here's a related question going the other way.
Example: (tested in Python 2 and 3)
>>> foo={'HELLO': [1,2,3]}
>>> foo
{'HELLO': [1, 2, 3]}
>>> foo.HELLO[0] <--- doesn't work
AttributeError: 'dict' object has no attribute 'HELLO'
>>> x='HELLO'
>>> foo[x][0] <--- works fine
1
You asked about self.x
. If x
is a regular variable, you don't reference it with self.
(as in the example above). If x
is a member of your class, then yes, you will need to use self.x
. However, if you are carrying around a key and a dictionary, you might consider redesigning your data structures to carry the resulting value instead.