I'm wondering if someone knows how to print a namespace that will show the key value pair of 'apple' and '$1.79'.
I understand that if I uncomment
#print(object_of_Hist_class)
I will see the data I'm asking about... but I'm curious if I can do
print(something.__dict__)
(where, apparently, I have no idea what the something should be) to see the 'apple' and '$1.79' data. Here is the code I am talking about:
class Hist(dict):
def __init__(self, instance_var):
self.instance_var = instance_var
object_of_Hist_class = Hist('cha cha cha')
object_of_Hist_class['apple'] = '$1.79'
#print(object_of_Hist_class)
print(object_of_Hist_class.__dict__)
print(Hist.__dict__)
print(dict.__dict__)
ORIGINAL POST ABOVE
SOLUTION BELOW
The following is what I was looking for... First I will recreate the results I had from before with vars
print(vars(object_of_Hist_class))
print(vars(Hist))
And below is what I was looking for when I first asked this question (in particular the "data" I was hoping to find, within a dictionary displaying namespace content, can be seen to the far right of the following prints):
print(vars())
print(locals())
print(globals())
Thanks to the following post for providing this information: What's the difference between globals(), locals(), and vars()?
If you aren't in a position to run the above prints, the final three all give dictionaries with a final key value pair of: 'object_of_Hist_class': {'apple': '$1.79'}
That is what I was looking for.
I'm new to stack overflow posts (and new to things like subclassing dict, which I don't plan on doing much more of). Anyways, thanks for encouraging me to be more clear with my posts and helping me to learn more about posting procedures!