class MyGlobals:
'''
This class implements a global variables object which can
easily be managed in all scopes without passing arguments
to functions or class methods.
This is a very nice way to manage explicit global variables!
'''
def __init__(self, dict=None):
self.data = {
'ilog':[],
'stdout':[],
'stderr':[],
'allrecords':[]
}
#lets add a setter and getter method...
def __getitem__(self, key):
return self.data[key]
def __setitem__(self, key, item):
self.data[key] = item
if __name__ =="__main__":
#Setup data...
g = MyGlobals()
import time
g['today'] = time.ctime() #now we have a new global variable
print g['today'] #here is how we reference the new variable in our object