Algorithms-Agents-and-Artif.../etc/util.py
2022-10-24 21:04:39 +08:00

26 lines
599 B
Python

from shelve import DbfilenameShelf
from play_config import ENABLE_DIAGNOSTIC_MESSAGES
def debug_print(*args):
if ENABLE_DIAGNOSTIC_MESSAGES:
print(*args)
class RecursiveDict(dict):
# defaultdict but smaller
def __missing__(self, key):
value = self[key] = type(self)()
return value
def __deepcopy__(self, memo):
return self
class NoCopyShelf(DbfilenameShelf):
def __deepcopy__(self, memo):
return self
def open(filename, flag='c', protocol=None, writeback=False):
return NoCopyShelf(filename, flag, protocol, writeback)