I know this question has been tossed around much but still it’s not very clear to me.
I have a file ‘vmsupport.py’. Among it’s many functions, it has one in particular where it needs to add a new element to a global dictionary ‘netpathdict’.I have declared
netpathdict={}
at the start of the script because I want to use this dictionary in another function in an another file ‘core.py’. Contents of the vmsupport.py file:
storefile="%s/netsummary_%s.html" % (full_paths[1].rsplit('/',1)[0],build)
netpathdict[build] = storefile
self.logger.debug("storefile at %s key of dictionary is %s" %(build,netpathdict[build]))
contents of ‘core.py’ file:
def view_networksummary(request,build):
result_file= netpathdict[build]
f = open(result_file,'r')
return HttpResponse(f)
f.close()
So, my question is, how exactly do I import the dictionary to core.py and use it and how would I be sure that the dictionary in use is the edited one.(Actually the vmsupport.py file works on a daemon that continuously adds elements to the dictionary. Hence, it’s NOT a one time affair )
Thank you
You don’t. You import the containing module and mutate the object contained in the attribute.