From 9195ffc6afba96644a82aae3ddfc40e8408d4fe8 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Tue, 3 Jul 2012 05:53:30 +0200 Subject: [PATCH] Add autodict class --- ircd.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ircd.py b/ircd.py index 3b8a741..efe87e2 100755 --- a/ircd.py +++ b/ircd.py @@ -21,6 +21,15 @@ def split_irc(message): else: return message.split(" ") +class autodict(dict): + # http://stackoverflow.com/a/652284 + def __getitem__(self, item): + try: + return dict.__getitem__(self, item) + except KeyError: + value = self[item] = type(self)() + return value + class ircd: channels = {} users = {}