if i have some code:
variableA = self.kwarg['maybe']
now, ‘maybe’ is sometimes there and sometimes not. I really don’t care if it isn’t there – i check if variableA is None down the line – so how do i avoid the oh-so-annoying “keyerror” that pops up when it isn’t there?
I just want django to let me set a variable to None!
UPDATE: thanks all!
I never used django, but if self.kwarg is a dict, you can use the get() function, which returns None (or an optional default value) for elements not in the dictionary: