Can I hear your thoughts on ways to add attributes (instance variables, not methods) to a Python dictionary? For record keeping, I want to insert additional descriptive variables.
For concreteness, here is an example. I want line 2 to work :)
>>> x = {"fred": "male", "wilma": "female", "barney": "male"}
>>> x.show = "Flintstones"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'dict' object has no attribute 'show'
The closest I've come to a solution is a class that has an instance variable along with the dictionary for feature information. That works fine, however it is a little bit tedious because all access to the dictionary must be wrapped in obj.x rather than just obj. I also can get a solution with a nested dictionary, but it introduces even more complicated code to interact with the lower level dictionary. We don't want to organize/sort the data by x.show, we just want to have access to that variable.
Here's why I think this might be possible. In the past, I've created Pandas DataFrame subclass so that I could have the Pandas DataFrame (2D storage) along with instance variables. The Pandas DataFrame works like a pandas data frame, but it has those additional metavariables as well. To make the Pandas DF Subclass work, there is some fancy dancing to declare the instance variables, but in the end it did work.
flintstonesinstead ofxand that might help solve the problem you're facing?x["show"] = "Flintstones"? Why would you want to add an attribute?