I’m currently coding a project in python where I need a sort of cache of generic objects, I have settled on using WeakValueDictionaries for this. These generic objects are often referenced by many other non-generic objects. My main problem though is that I can’t seem to wrap my head around a way of making these WeakValueDictionaries available to many different portions of the program. I would prefer not to use “global” variables if possible.
Best regards
FrederikNS
Maybe I’m not understanding your question, but making a dictionary of weakly referenced values available to your code isn’t really any different from making a dictionary of anything else available to your code. I would store a reference to the
WeakValueDictionaryon:self)self, but shared between instances)depending on what made the most sense given the rest of your code.